Undefined function or variable in ode45
Afficher commentaires plus anciens
I have this differantial equation set.
k1, k2, k3, k4 are constants.
I need to find value of x and y at t=500.
I want to solve this set simultaneously. I wrote that code:
function da=fun(t,a)
k1=0.02; % day^-1 %constant for growth of rabbits
k2=0.00004; % (day*foxes)^-1 %constant for death of rabbits
k3=0.0004; % (day*rabbits)^-1 %constant for growth of
% foxes after eating rabbits
k4=0.04; % day^-1 %constant for death of foxes
x=a(1,:);
y=a(2,:);
da(1,:)=k1*x-k2*x*y;
da(2,:)=k3*x*y-k4*y;
clear all
timerange=[0 500];
initial=[500 200];
[t,a]=ODE45(@fun,timerange,initial);
When i run, i get "Undefined function or variable 't'." error.
Can anyone help?
2 commentaires
Just to be sure (because I formatted your question this way), the lines
function da=fun(t,a)
to
da(2,:)=k3*x*y-k4*y;
(note that in your question, it was initially written a(2,:)=.. and not da(2,:)=..) are in a separate file named fun.m, and from
clear all
to the end, this is a separate file/script (?)
Ugur Bozuyuk
le 15 Fév 2015
Modifié(e) : Ugur Bozuyuk
le 15 Fév 2015
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
