Problem with ODE45

1 view (last 30 days)
Saeed Ahmadzadeh Mahboobi
Commented: Richard Brown on 7 Nov 2019
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 Comments
Walter Roberson
Walter Roberson on 6 Nov 2019
We will need more of your code to test with.
Richard Brown
Richard Brown on 7 Nov 2019
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.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!