Problem with ODE45

I should solve 2 coupled matrix differential equations. for that, I have created a script (m-file) in which I have defined all matrices with constant values. I have also created another script for a function and call this function in the first m-file. Finally I have used ode45 to solve the function, but it doesn't work!
The systom to be solved (A, L, R and P are matrices with constant components):
My function (which its name is 'myode'):
function dydt=myode(t,y,A,R,L,P)
[m n]=size(P);
[k l]=size(L);
for a=1:m
dydt(a)=P(a,:)*y(a);
end
for b=1:k
dydt(m+b)=inv(L)*(A*y(m+b)-R*y(b));
end
end
My first script (m-file):
tspan=linspace(5,5.010,11);
i_0=transpose([0.355 -0.355 2.046 0.711 0 0.709]);
u_0=transpose([1002.40 1001.98 1012.04 986.11]);
y0=[u_0;i_0];
[T Y]=ode45(@(t,y) myode(t,y,A,R,L,P),tspan,y0)
==> but when I run my first script, the following error pops up:
Error in Test>@(t,y)myode(t,y,A,R,L,P)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Test (line 58)
[T Y]=ode23(@(t,y) myode(t,y,A,R,L,P),tspan,y0)
Anyone has an idea what the problem is?

6 Commenti

And when I run the function alone, the error is:
Not enough input arguments.
Error in myode2 (line 2)
[m n]=size(P);
u and i have different sizes
1.png
You also passing different sizes
i_0=transpose([0.355 -0.355 2.046 0.711 0 0.709]);
u_0=transpose([1002.40 1001.98 1012.04 986.11]);
How to substract ?
I like the way you organized the question
About the matrix dimensions, when they are multiplied with another marix from left side, the both A*u and R*i become matrices of the same dimensions.
darova
darova il 6 Nov 2019
Can you show A and R matrices?
Walter Roberson
Walter Roberson il 6 Nov 2019
We will need more of your code to test with.
You're definitely going to have issues trying to build your derivative one term at a time (look at the term involvint inv(L) for a start). why can't you just do the following?
function dydt=myode(t,y,A,R,L,P)
u = y(1:3);
i = y(4:7);
dydt = [L\(A*u - R*i); P*i];
end
will be much easier to troubleshoot.

Accedi per commentare.

Risposte (0)

Prodotti

Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by