Azzera filtri
Azzera filtri

Variables of type "sym" cannot be combined with other models. Please help

25 visualizzazioni (ultimi 30 giorni)
I want to solve this set of equations:
Here is my code:
syms mu_u N_a; % Variables to Solve for
P = tf(1,[1 1]);
F_r = tf(1,[1 1]);
C = 1;
sigma_r = 1;
f = x ;
mu_r =1;
P_o = 1;
C_o = 1;
sys = (F_r * C) / ( 1 + (P * N_a * C) );
n = norm(sys); % H2 Norm Calculation
sigma_u = n * sigma_r;
fun_n = ( (diff(f)) / (sqrt(2*pi)*mu_u) ) * (exp ( -1* ((x-(mu_u))^2) / (2*(sigma_u)^2)) );
F_N = int(fun_n, x, -inf, inf);
%N_a - F_N = 0; % Equation 14 of Assignment
fun_m = ( (f) / (sqrt(2*pi)*mu_u) ) * (exp ( -1* ((x-(mu_u))^2) / (2*(sigma_u)^2)) );
F_M = int(fun_m, x, -inf, inf);
%(mu_r / P_o) - (mu_u / C_o * P_o) - F_M = 0; % Equation 15 of Assignment
eqn1 = N_a - F_N == 0;
eqn2 = (mu_r / P_o) - (mu_u / C_o * P_o) - F_M == 0;
eqns = [eqn1 eqn2];
S = solve(eqns,[N_a mu_u]);
ans_1 = S.N_a
ans_2 = S.mu_u
And the error is:
Error using *
Invalid operand. Variables of type "sym" cannot be combined with other models.
Error in Test (line 13)
sys = (F_r * C) / ( 1 + (P * N_a * C) );
Please help me resolve this error.
  1 Commento
Dyuman Joshi
Dyuman Joshi il 18 Nov 2023
Modificato: Dyuman Joshi il 18 Nov 2023
The error is clear, you can not combine transfer function model with symbolic variables.
Why not define P and F_r as symbolic variables?
sys = tf([1 0],[1 2 3])
sys = s ------------- s^2 + 2 s + 3 Continuous-time transfer function.
[Num,Den] = tfdata(sys);
syms s
sys_syms = poly2sym(Num{:},s)/poly2sym(Den{:},s)
sys_syms = 
Also, "x" is un-defined.
f = x;
Unrecognized function or variable 'x'.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 18 Nov 2023
The functions in the Control System Toolbox do not use the Symbolic Toolbox, and cannot be mixed with the symbolic toolbox at all. You need to convert your tf into symbolic formulas
Your "x" is not defined in your code, so I cannot test much.
syms mu_u N_a; % Variables to Solve for
syms s
P_tf = tf(1,[1 1]);
F_r_tf = tf(1,[1 1]);
P = poly2sym(P_tf.Numerator{1},s) / poly2sym(P_tf.Denominator{1},s)
P = 
F_r = poly2sym(F_r_tf.Numerator{1},s) / poly2sym(F_r_tf.Denominator{1},s)
F_r = 
C = 1;
sigma_r = 1;
f = x ;
Unrecognized function or variable 'x'.
mu_r =1;
P_o = 1;
C_o = 1;
sys = (F_r * C) / ( 1 + (P * N_a * C) );
n = norm(sys); % H2 Norm Calculation
sigma_u = n * sigma_r;
fun_n = ( (diff(f)) / (sqrt(2*pi)*mu_u) ) * (exp ( -1* ((x-(mu_u))^2) / (2*(sigma_u)^2)) );
F_N = int(fun_n, x, -inf, inf);
%N_a - F_N = 0; % Equation 14 of Assignment
fun_m = ( (f) / (sqrt(2*pi)*mu_u) ) * (exp ( -1* ((x-(mu_u))^2) / (2*(sigma_u)^2)) );
F_M = int(fun_m, x, -inf, inf);
%(mu_r / P_o) - (mu_u / C_o * P_o) - F_M = 0; % Equation 15 of Assignment
eqn1 = N_a - F_N == 0;
eqn2 = (mu_r / P_o) - (mu_u / C_o * P_o) - F_M == 0;
eqns = [eqn1 eqn2];
S = solve(eqns,[N_a mu_u]);
ans_1 = S.N_a
ans_2 = S.mu_u
  2 Commenti
Ahmad
Ahmad il 19 Nov 2023
My function f is a saturation function. How should i model it and solve it?
Walter Roberson
Walter Roberson il 19 Nov 2023
Unfortunately at the moment I have no idea what saturation models look like.
You can convert tf() to symbolic form using the approach I show here of fetching the numerator and denominator, or using Dyuman's suggestion of tfdata.
Likewise if you have a symbolic laplace transform that does not involve any exp() forms and which involves only s and no other symbolic variable, then there are ways to convert that into a tf() that are not bad. (delays coded with exp take more work to detect and extract from the laplace)
If you start needing state space form then conversion of symbolic to ss is harder.
If you have a symbolic laplace that involves another symbolic variable beyond s (perhaps you are trying to tune the equation) then unfortunately, Control System Toolbox cannot handle that situation.
What Control System Toolbox can handle is systems involving entities that are marked as being subject to change. So you might get a system that you write in terms of (say) k, but internally at every point the control system toolbox has a definite value for k, along with tools that can change the definite value easily. The resulting internals cannot "reason" about k

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by