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

3 views (last 30 days)
Evelyn Lovasz on 12 Jan 2022
Commented: Evelyn Lovasz on 16 Jan 2022
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)
Evelyn Lovasz on 16 Jan 2022
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

the cyclist on 12 Jan 2022
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.)
Evelyn Lovasz on 16 Jan 2022
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!