Why does Matlab not manage to evaluate a certain variable in my code?

9 次查看(过去 30 天)
Hello,
I need to evaluate the variables psi1 and psi2 marked in the image (lines 42 and 43, I have also given the code below). Matlab has no issues in evaluating psi1 but is not able to evaluate psi2. I have let Matlab run overnight but it cannot provide a result. This seems very curious to me because the variables are very similar.
Can you please explain this behaviour?
clear all; close all; clc;
syms iL vC1 iLr vC2 Vg L R C1 C2 Lr D Ts s t
x = [iL; vC1; iLr;vC2]
u = Vg
y = vC2
A1 = [0 0 0 0;
0 0 -1/C1 0;
0 1/Lr 0 0;
0 0 0 -1/(R*C2)];
B1 = [1/L; 0;0;0];
E1 = [0 0 0 1];
F1 = [0]
A2 = [0 -1/L 0 -1/L;
1/C1 0 0 0;
0 0 0 0;
1/C2 0 0 -1/(R*C2)];
B2 = [1/L; 0;0;0];
E2 = E1
F2 = F1
Vg=12; V0 = 48; L = 100e-6;Lr = 5.6993e-07; C1 = 10e-6; C2=100e-6; P0 = 1000; R=V0^2/P0; R0 = sqrt(Lr/C1)
fs =100e3; Ts = 1/fs; Ws = 2*pi*fs; % ws for Vo = 12 V read from static characteristic
M = V0/Vg; D = 1-1/M
A1 = eval(A1)
A2 = eval(A2)
B1 = eval(B1)
B2 = eval(B2)
psi1 = eval(int(expm(A1*t),0,D*Ts)*B1)
psi2 = eval(int(expm(A2*t),t,0,(1-D)*Ts)*B2)
  2 个评论
Evelyn Lovasz
Evelyn Lovasz 2022-1-16
Thank you for your suggestions, Stephen! i used vpa instead of simplify and it worked!
ThemeCopy
var = vpa(expm(A2*t),3) % I use var as intermediate variable
psi2 = vpa(int(var,t,0,(1-D)*Ts)*B2,3)
% The result I get is:
psi2 =
0.025 + 4.43e-16i
0.00312 - 6.97e-14i
0
3.11e-4 - 3.2e-15i

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2022-1-12
Is this really the expression you want to evaluate?
int(expm(A2*t),t,0,(1-D)*Ts)*B2
The reason I ask is that it has a different number of arguments from
int(expm(A1*t),0,D*Ts)*B1
and I speculate that you didn't actually intend that.
(I did not dig into the implications of the different argument list myself.)
  3 个评论
the cyclist
the cyclist 2022-1-12
I don't really have a solution here, but I stripped away lots of your code, and I think the essence of your problem is that the second expression you are integrating is significantly more complicated than the first one. (Compare the two expressions displayed at the end of this code.) I don't have any experience with the Symbolic Math Toolbox, so I can't offer any more advice.
syms L R C1 C2 Lr t
A1 = [0 0 0 0;
0 0 -1/C1 0;
0 1/Lr 0 0;
0 0 0 -1/(R*C2)];
A2 = [ 0 -1/L 0 -1/L;
1/C1 0 0 0;
0 0 0 0;
1/C2 0 0 -1/(R*C2)];
V0 = 48;
L = 100e-6;
Lr = 5.6993e-07;
C1 = 10e-6;
C2 = 100e-6;
P0 = 1000;
R = V0^2/P0;
A1 = eval(A1);
A2 = eval(A2);
expm(A1*t)
ans = 
expm(A2*t)
ans = 
Evelyn Lovasz
Evelyn Lovasz 2022-1-16
Yes, I think that the complexity of expm(A2*t) was the issue here. Stephen suggested to use vpa instead of eval and it worked. Thanks again!

请先登录,再进行评论。

类别

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