Error in Error in odearguments (line 92) f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0. Error in ode45 (line 104) odearguments(odeIsFuncHandle,odeTreatAsMFile,
35 views (last 30 days)
Show older comments
I've been trying to figure out what I'm doing wrong, but cant seem to find it, its a 2 part code:
clear all
function dy = juan(t,y)
global k1 k2 k3 kmin3 k4 k5 k6 k7
dy=zeros(6,1);
dy(1)=k1-k2.*y(1).*y(5);
dy(2)=k2.*y(1).*y(5)+kmin3.*y(3)-k3.*y(2);
dy(3)=k3.*y(2)+k5.*y(4)-k4.*y(3).*y(5)-k3.*y(3);
dy(4)=k4.*y(3).*y(5)-k5.*y(4)-k6.*y(4);
dy(5)=k7.*y(6)-k2.*y(1).*y(5)-k4.*y(3).*y(5);
dy(6)=-k7.*y(6)+k2.*y(1).*y(5)+k4.*y(3).*y(5);
end
That first part defines my ecuations, and the next one asignes values to k's, but always get errors even when its the same code as my professor
global k1 k2 k3 kmin3 k4 k5 k6 k7
k1= 0.25;
k2= 1;
k3= 1;
kmin3= 1;
k4= 1;
k5= 1;
k6= 1;
k7= 2.5;
[t,y]=ode45(@juan, [0 60], [0; 0; 0; 0; 0.5; 0.5])
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in COMANDOS (line 10)
[t,y]=ode45(@juan, [0 60], [0; 0; 0; 0; 0.5; 0.5])
1 Comment
Torsten
on 23 Feb 2024
Works for me.
global k1 k2 k3 kmin3 k4 k5 k6 k7
k1= 0.25;
k2= 1;
k3= 1;
kmin3= 1;
k4= 1;
k5= 1;
k6= 1;
k7= 2.5;
[t,y]=ode45(@juan, [0 60], [0; 0; 0; 0; 0.5; 0.5]);
plot(t,y)
grid on
function dy = juan(t,y)
global k1 k2 k3 kmin3 k4 k5 k6 k7
dy=zeros(6,1);
dy(1)=k1-k2.*y(1).*y(5);
dy(2)=k2.*y(1).*y(5)+kmin3.*y(3)-k3.*y(2);
dy(3)=k3.*y(2)+k5.*y(4)-k4.*y(3).*y(5)-k3.*y(3);
dy(4)=k4.*y(3).*y(5)-k5.*y(4)-k6.*y(4);
dy(5)=k7.*y(6)-k2.*y(1).*y(5)-k4.*y(3).*y(5);
dy(6)=-k7.*y(6)+k2.*y(1).*y(5)+k4.*y(3).*y(5);
end
Answers (2)
Steven Lord
on 23 Feb 2024
Get rid of the line clear all at the start of your juan.m file.
0 Comments
VBBV
on 1 May 2024
Edited: VBBV
on 1 May 2024
@Juan you have probably tried using the arguments to the ode45 function as below, Try using the same syntax as it was provided to you from your professor. it works fine
global k1 k2 k3 kmin3 k4 k5 k6 k7
k1= 0.25;
k2= 1;
k3= 1;
kmin3= 1;
k4= 1;
k5= 1;
k6= 1;
k7= 2.5;
[t,y]=ode45(@(k1, k2, k3, kmin3, k4, k5, k6, k7) juan(k1, k2, k3, kmin3, k4, k5, k6, k7), [0 60], [0; 0; 0; 0; 0.5; 0.5])
clear all
function dy = juan(k1, k2, k3, kmin3, k4, k5, k6, k7)
global k1 k2 k3 kmin3 k4 k5 k6 k7
dy=zeros(6,1);
dy(1)=k1-k2.*y(1).*y(5);
dy(2)=k2.*y(1).*y(5)+kmin3.*y(3)-k3.*y(2);
dy(3)=k3.*y(2)+k5.*y(4)-k4.*y(3).*y(5)-k3.*y(3);
dy(4)=k4.*y(3).*y(5)-k5.*y(4)-k6.*y(4);
dy(5)=k7.*y(6)-k2.*y(1).*y(5)-k4.*y(3).*y(5);
dy(6)=-k7.*y(6)+k2.*y(1).*y(5)+k4.*y(3).*y(5);
end
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!