Problem with ODE45

2 views (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
for b=1:k
My first script (m-file):
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]);
[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?
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];
will be much easier to troubleshoot.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!