Variables of type "sym" cannot be combined with other models. Please help
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmad
el 18 de Nov. de 2023
Comentada: Walter Roberson
el 19 de Nov. de 2023
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 comentario
Dyuman Joshi
el 18 de Nov. de 2023
Editada: Dyuman Joshi
el 18 de Nov. de 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])
[Num,Den] = tfdata(sys);
syms s
sys_syms = poly2sym(Num{:},s)/poly2sym(Den{:},s)
Also, "x" is un-defined.
f = x;
Respuesta aceptada
Walter Roberson
el 18 de Nov. de 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)
F_r = poly2sym(F_r_tf.Numerator{1},s) / poly2sym(F_r_tf.Denominator{1},s)
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
2 comentarios
Walter Roberson
el 19 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!