- You are basically working with two functions: the main function ( myODE ) and the function defining the differential equations. Make sure to complete each function with an end-command.
- The parameters ( a,b,c ) need to be passed to the second function. I am using a vector called params.
Solving nonlinear differential system from matlab website giving error
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi community members! I have been trying to solve a nonlinear differential system for work and to learn, copied in the exact code from a tutorial found at: http://www.mathworks.com/help/matlab/ref/ode45.html (Example 1) Whenever I try to run it, my Matlab gives me an error at line 3:

Any help on this would be deeply appreciated. I am basically looking to solve the system numerically since analytically seems impossible. If somebody has a better way of doing this, that would be much appreciated. Thanks in advance!
0 commentaires
Réponses (1)
Mischa Kim
le 26 Juin 2014
Modifié(e) : Mischa Kim
le 26 Juin 2014
Devansh, use
function myODE()
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
a = 1; b = 2; c = 3;
params = [a; b; c];
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options,params);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
end
function dy = rigid(t,y,params)
a = params(1);
b = params(1);
c = params(1);
dy = zeros(3,1); % a column vector
dy(1) = a*y(2) * y(3);
dy(2) = -b*y(1) * y(3);
dy(3) = -c*0.51 * y(1) * y(2);
end
and save the entire file as myODE.m.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Computations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!