Solving a system with embedded differential and non-differential equations

5 visualizzazioni (ultimi 30 giorni)
I was trying to resolve this system for md and mq with this answer as a reference.
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 Commenti
Torsten
Torsten il 11 Gen 2023
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).

Accedi per commentare.

Risposte (2)

Steven Lord
Steven Lord il 11 Gen 2023
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);
  2 Commenti
Marcelo García Olavarría
Yes, I have another file that contains my function, called difsyssolve.m. Theta is another variable like md, mq or M, but I don´t know how to define it.
Marcelo García Olavarría
Also, I couldn´t find another example of a solution for a system with differential and non-differential equations besides the one wich I attached in my post.

Accedi per commentare.


Joel Van Sickel
Joel Van Sickel il 11 Gen 2023
Modificato: Joel Van Sickel il 11 Gen 2023
you need to create and define the variable theta in your function before you use it.
  1 Commento
Marcelo García Olavarría
Could you give me an example please? I really don't know how to create it or define it. I tried with syms, but I guess that's incorrect.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by