Solving a system of ODEs in MATLAB

I'm trying to solve two ODEs in MATLAB. I wrote this function, but I keep getting an error message.
function dy = diff_eqs(y,t)
%Constants R = 100; k12 = 33; k21= 33; V1 =10; V2 = 25; k2=8;
%Equations dy = zeros(2,1);
dy(1,1) = (R - k12.*y(1) + k21 .* y(2))./V1;
dy(2,1) = (k12.*y(1) - k21.* y(2) - k2.*y(2))./V2;
end
After I get this down, I plan on using ode45 to solve.

1 Comment

With a standard formatting your question would look nicer.
Whenever your write "I get an error message" in a forum, it is a good idea to post a copy of it. Matlab's error messages are such useful that it is worth to read them.

Sign in to comment.

 Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 10 Nov 2012
Edited: Azzi Abdelmalek on 10 Nov 2012
function dy = diff_eqs(t,y)
dy=zeros(2,1);
R=100;
k12=33;
k21=33;
V1=10;
V2=25;
k2=8;
dy(1) = (R - k12*y(1) + k21*y(2))/V1;
dy(2) = (k12*y(1)-k21*y(2)-k2*y(2))/V2;
%call the function
x0=[0;0];
[t,y]=ode45(@diff_eqs,[0 10],x0)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!