How to make .m file
Afficher commentaires plus anciens
Hello.
I made a separate .m file for me to evaluate using ode45 but i got an error. This is my .m file.
function ndot= volterra_allelo(t,n)
global r1 k1 alpha12 gamma12 r2 k2 alpha21 gamma21;
ndot(1,1)= r1*n(1)*((k1-alpha12*n(2)-gamma12*n(1)*n(2)/k1));
ndot(2,1)= r2*n(2)*((k2-alpha21*n(1)-gamma21*n(1)*n(2)/k2));
i am ruuning this using the code:
[time n]=ode45('volterra_allelo',[0 10],[n1hat_n/2;n2hat_n/2];
I have some values for r1 k1 alpha12 gamma12 r2 k2 alpha 21 gamma21 and n1hat_n and n2hat_n.
when i run the ode comman, i got an error.
I think i have errors in the .m file. please help me.
Réponses (1)
madhan ravi
le 24 Nov 2018
Modifié(e) : madhan ravi
le 24 Nov 2018
% r1,k1,alpha12,gamma12,r2,k2,alpha21,gamma21 provide all the values here ,parametrized your function rather than using global
[time n]=ode45(@(t,n)volterra_allelo(t,n,r1,k1,alpha12,gamma12,r2,k2,alpha21,gamma21),[0 10],[n1hat_n/2;n2hat_n/2]; %function call
function ndot= volterra_allelo(t,n,r1,k1,alpha12,gamma12,r2,k2,alpha21,gamma21) %function definition
ndot=zeros(2,1);
ndot(1)= r1*n(1)*((k1-alpha12*n(2)-gamma12*n(1)*n(2)/k1));
ndot(2)= r2*n(2)*((k2-alpha21*n(1)-gamma21*n(1)*n(2)/k2));
end
Catégories
En savoir plus sur Runge Kutta Methods 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!