The output of solve(eqn, x) is still an equation instead of number
Afficher commentaires plus anciens
Hello,
The whole script is below:
syms G1 G2 C1 C2 K H a s
G=(a*K*G1*G2)/(s^2*C1*C2+s*(C2*(G1+G2)+C1*G2*(1-K))+G1*G2) %Transfer function
[G_num,G_den]=numden(G)
[G_den_coeffs,~]=coeffs(G_den,s)
G_num=G_num/(C1*C2)
G_den_coeffs=G_den_coeffs/(C1*C2)
G_num=poly2sym(G_num,s)
G_den=poly2sym(G_den_coeffs,s)
G=G_num/G_den
equation2=G_den_coeffs(1,3)==1
isolate(equation2,C2)
%I need to solve equation 1 for G2.
equation1=G_den_coeffs(1,2)==0.618
G1=1/6000;
C1=10^-6;
C2=10^-9;
K=100;
G2=solve(equation1,G2)
The output of G2 is still an equation not a number as needed.
The variables are defined so when I copy and paste the G2 equation I get the value.
Any idea how can I get the result of G2 without the need to copy and paste the equation.
1 commentaire
Hi @NGiannis
It is possible to solve for
, but the solution can only satisfy one of the two design requirements. . The step response is highly oscillatory, and the percentage overshoot is as high as 94%. I don't think this solution is acceptable. In my answer below, I proposed making
a free parameter so that two equations can be solved simultaneously.
G1 = 1/6000;
C1 = 1e-6;
C2 = 1e-9;
K = 100;
a = 1/K;
sympref('AbbreviateOutput', false);
syms s G2
G = (a*K*G1*G2)/(s^2*C1*C2+s*(C2*(G1+G2)+C1*G2*(1-K))+G1*G2)
[G_num, G_den] = numden(G);
[G_den_coeffs, ~] = coeffs(G_den, s)
eqn1 = G_den_coeffs(2)/G_den_coeffs(1) == 0.618;
sol = solve(eqn1, G2);
s = tf('s');
G2 = double(sol)
G = (a*K*G1*G2)/(s^2*C1*C2 + s*(C2*(G1 + G2) + C1*G2*(1 - K)) + G1*G2); %Transfer function
G = minreal(G)
step(G)
% Check if it returns 1
(G1*G2)/(C1*C2)
S = stepinfo(G);
S.Overshoot
Réponse acceptée
Plus de réponses (2)
Use
G2 = double(solve(subs(equation1)))
instead of
G2=solve(equation1,G2)
Hi @NGiannis
In the comment above, if
is set as constant, then the parameter
appears in two terms.
can be found by solving either one of the terms, but it won't satisfy both design requirements. To address this issue, I selected
as a second parameter. Solving two equations simultaneously will return the solution for both
and
.
format long g
% Constants
C1 = 1e-6;
C2 = 1e-9;
K = 100;
out = 1; % desired output (can be 1, 100, or pi, etc.)
a = out/K; % output coefficient
sympref('AbbreviateOutput', false);
% Declare parameters G1 and G2 that defines the transfer function
syms s G1 G2
assume(G1, "positive")
assume(G2, "positive")
% The transfer function
G = (a*K*G1*G2)/(s^2*C1*C2+s*(C2*(G1+G2)+C1*G2*(1-K))+G1*G2)
[G_num, G_den] = numden(G);
[G_den_coeffs, ~] = coeffs(G_den, s)
% Solve simultaneous equations for both parameters G1 and G2
eqn1 = G_den_coeffs(2) == 0.618;
eqn2 = G_den_coeffs(3) == 1;
sol = solve([eqn1, eqn2], [G1, G2]);
G1 = double(sol.G1) % 1.02636211e-5
G2 = double(sol.G2) % 9.74315002e-11
%% if zeta = 0.618
% G1 = double(sol.G1) % 1.05869981e-5
% G2 = double(sol.G2) % 9.44554808e-11
%% Test
s = tf('s');
G = (a*K*G1*G2)/(s^2*C1*C2+s*(C2*(G1+G2)+C1*G2*(1-K))+G1*G2);
G = minreal(G) % check if design requirements are satisfied
step(G), grid on % step response
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









