Solving a system with embedded differential and non-differential equations
5 次查看(过去 30 天)
显示 更早的评论
This is my code:
function dX=fun(t,X)
%constants
f=50;
ws=2*pi*f;
Ls=15e-3;
Rs=1;
Rcdc=500;
Cdc=500e-6;
Vs=220*sqrt(2);
Vsd=220*sqrt(3);
ipv=10
fp=0.96
%7 ecuaciones, 3 diferenciales.
%en el sistema, Vq=0, por lo que no se agrega al sistema de ec.
%X(1)=id X(2)=iq X(3)=Vdc
dX(1)=ws*X(2) + Vsd/Ls - Rs*X(1)/Ls - cos(theta)*md/Ls;
dX(2)=-ws*X(1) - Rs*X(2)/Ls - sin(theta)*mq/Ls;
dX(3)=(X(1)*md+X(2)*mq)/Cdc + ipv/Cdc - X(3)/(Cdc*Rcdc);
md=sqrt(3/2)*M*cos(theta)
mq=sqrt(3/2)*M*sin(theta)
M=sqrt(3/2)*sqrt((mq^2)+(md^2))
fp=X(1)/X(2);
%Definition of dX
dX=[dX(1);dX(2);dX(3)];
end
tSpan = [0 5];
initial=[.01; .01; .01];
%X(1)=id X(2)=iq X(3)=theta X(4)=Vdc X(5)=md X(6)=mq X(7)=M
[t,x]=ode45(@difsyssolve,tSpan,initial);
id=x(:,1);
iq=x(:,2);
theta=x(:,3);
Vdc=x(:,4);
md=x(:,5);
mq=x(:,6);
M=x(:,7);
figure
plot(t,Vdc)
xlabel('tiempo')
ylabel('vdc')
And it gives me the following error:
Unrecognized function or variable 'theta'.
Error in difsyssolve (line 19)
dX(1)=ws*X(2) + Vsd/Ls - Rs*X(1)/Ls - theta*md/Ls;
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in test (line 6)
[t,x]=ode45(@difsyssolve,tSpan,initial);
I don´t know how to define theta, and how to solve the system.
Can you help me?
Thank you in advance.
4 个评论
Torsten
2023-1-11
If you knew M and theta, you could solve for md and mq, and you could solve the three odes.
But with M and theta unknown, your system cannot be solved (at least not numerically).
回答(2 个)
Steven Lord
2023-1-11
I assume you've written this function in a file named difsyssolve.m and that your call to ode45 is not in that same file?
function dX=fun(t,X)
%constants
f=50;
ws=2*pi*f;
Ls=15e-3;
Rs=1;
Rcdc=500;
Cdc=500e-6;
Vs=220*sqrt(2);
Vsd=220*sqrt(3);
ipv=10
fp=0.96
%7 ecuaciones, 3 diferenciales.
%en el sistema, Vq=0, por lo que no se agrega al sistema de ec.
%X(1)=id X(2)=iq X(3)=Vdc
dX(1)=ws*X(2) + Vsd/Ls - Rs*X(1)/Ls - cos(theta)*md/Ls;
% Snip the rest
On this line of code you try to use something named theta. Where in your function do you define a variable by that name? If you haven't defined that variable, MATLAB will check for a function named theta that it can call with 0 input arguments and 1 output argument. If it can't, MATLAB will throw an error.
Looking at the rest of your code, I think you probably want something like this in your diffsyssolve.m file. [Though you would need to change x to X.]
theta=x(:,3);
Joel Van Sickel
2023-1-11
编辑:Joel Van Sickel
2023-1-11
you need to create and define the variable theta in your function before you use it.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!