How to deal with the connection between symbolic caculations and numerical caculations?

조회 수: 5 (최근 30일)
First I need to do symbolic calculations to get the required equations. Then I use the equations for numerical calculations.
For example, I obtain the equation Ge1=-1/((2*s + 1)/(s/20 + 1) + s^2*(s/10 + 1)) by symbolic calculations.
Then If Ge1_1=-1/((2*s + 1)/(s/20 + 1) + s^2*(s/10 + 1)), one can do numerical calculations.
And I can't do numerical calculations when I want Ge1_1=Ge1.
I don't know how to deal with the connection between symbolic caculations and numerical caculations. Is there a way to solve the problem? Thank you for reading and help.
Matlab Code:
syms s
kp=(2*s+1)/(0.05*s+1);
H=1/(s^2*(0.1*s+1));
P12_1=[-1 / H - kp];
Ge1=inv(P12_1)
s=tf('s')
w=logspace(-1,1,1000);
Ge1_1=Ge1;
% Ge1_1=-1/((2*s + 1)/(s/20 + 1) + s^2*(s/10 + 1));
[mag,pha,w]=bode(Ge1_1,w);
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 3월 23일
P12_1=[-1 / H - kp;];
Could you confirm that you want
P12_1=[(-1 / H) - kp;];
which would be
P12_1 = (-1/ H) - kp;
??
Or did you possibly mean
P12_1=[-1 / (H - kp)];
Cola
Cola 2022년 3월 23일
편집: Cola 2022년 3월 23일
@Walter Roberson Thanks. I mean [-1/H-kp], that is ,[(-1/ H) - kp].

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2022년 3월 21일
"matlabFunction" converts symbolic expressions into function handles for numerical calculations.
help matlabFunction
  댓글 수: 1
Cola
Cola 2022년 3월 23일
편집: Cola 2022년 3월 23일
@Torsten Thank you so much.
Matlab code:
syms s
kp=(2*s+1)/(0.05*s+1);
H=1/(s^2*(0.1*s+1));
P12_1=[-1/H-kp];
Ge1=inv(P12_1);
Ge1 = 
omega=logspace(-1,1,1000);
Ge1_0=matlabFunction(Ge1);
Ge1_0 = function_handle with value:
@(s)-1.0./((s.*2.0+1.0)./(s./2.0e+1+1.0)+s.^2.*(s./1.0e+1+1.0))
Ge1_1=abs(Ge1_0(1i*omega));

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2022년 3월 23일
Of course, the symbolic approach will work and might even have some benefits (IDK), but just want to make sure you're aware that it's not really necessary.
% symbolic approach
syms s
kp=(2*s+1)/(0.05*s+1);
H=1/(s^2*(0.1*s+1));
P12_1=[-1 / H - kp;];
Ge1=inv(P12_1);
[num,den] = numden(Ge1);
Ge1 = num/den
Ge1 = 
% control system toolbox functionality
s = tf('s');
kp=(2*s+1)/(0.05*s+1);
H=1/(s^2*(0.1*s+1));
P12_1=[-1 / H - kp;];
Ge1=inv(P12_1);
Ge1 = minreal(Ge1) % normalizes numerator and denominator for comparison to symbolic result, not necessary otherwise
Ge1 = -10 s - 200 ------------------------------------ s^4 + 30 s^3 + 200 s^2 + 400 s + 200 Continuous-time transfer function.
  댓글 수: 3
Steven Lord
Steven Lord 2022년 3월 23일
If you wanted to go directly from the symbolic Ge1 to the tf object Ge1 you could extract the numerator and denominator from the symbolic Ge1 with numden as you did and then convert those symbolic polynomials into vectors of polynomial coefficients with sym2poly.
syms s
kp=(2*s+1)/(0.05*s+1);
H=1/(s^2*(0.1*s+1));
P12_1=[-1 / H - kp;];
Ge1=inv(P12_1);
[num,den] = numden(Ge1)
num = 
den = 
N = sym2poly(num)
N = 1×2
-10 -200
D = sym2poly(den)
D = 1×5
1 30 200 400 200
You can use N and D to create the tf object.
T = tf(N, D)
T = -10 s - 200 ------------------------------------ s^4 + 30 s^3 + 200 s^2 + 400 s + 200 Continuous-time transfer function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by