# Solving a system with embedded differential and non-differential equations

2 ビュー (過去 30 日間)
Marcelo García Olavarría 2023 年 1 月 11 日
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?
##### 4 件のコメント表示非表示 3 件の古いコメント
Marcelo García Olavarría 2023 年 1 月 11 日
Ok! that's helpful. Maybe I have built my system incorrectly.
Thank you.

サインインしてコメントする。

### 回答 (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);
##### 2 件のコメント表示非表示 1 件の古いコメント
Marcelo García Olavarría 2023 年 1 月 11 日
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.

サインインしてコメントする。

Joel Van Sickel 2023 年 1 月 11 日

you need to create and define the variable theta in your function before you use it.
##### 1 件のコメント表示非表示 なし
Marcelo García Olavarría 2023 年 1 月 11 日
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.

サインインしてコメントする。

### カテゴリ

Find more on General Applications in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by