ode45 system of equations

4 vues (au cours des 30 derniers jours)
Richard
Richard le 15 Juin 2012
Modifié(e) : Jan le 12 Déc 2017
I used the lotkademo file as a template for solving a set of ODEs
When I change the initial conditions or time span the program still returns a solution vector from 0<t<15 (which was the default for the demo file) I've edited the function containing the equations as well and can't seem to see why these don't change. code below:
t0 = 0;
tfinal = 20;
y0 = [500 10]';
tfinal = tfinal*(1+eps);
[t,y] = ode45('MonodMod',[t0 tfinal],y0,[T Y]);
[T Y]
Given a function called MonodMod:
function yp = MonodMod(t,y)
yp = diag([- ((1*y(1))/(.5+y(1))) + 0 + 0,((1*y(1)*.8)/(.5+y(1))) - (0.7*.8) - (0.3*.8/1.42)])*y;
So when I update values for y0 or tfinal and evaluate [T Y] the ouput is still 0<t<15, and the initial values are still [20 20]..

Réponses (2)

ME
ME le 12 Déc 2017
I have just been over this and found that
t0=0;
tfinal=20;
y0=[500 10]';
tfinal-tfinal*(1+eps);
[t,y]=ode45('MonodMod',[t0 tfinal],y0);
[t,y]
with the function
function yp = MonodMod(t,y)
yp = diag([- ((1*y(1))/(.5+y(1))) + 0 + 0,((1*y(1)*.8)/(.5+y(1))) - (0.7*.8) - (0.3*.8/1.42)])*y;
end
seems to work for me for a range of tfinal choices.

Jan
Jan le 12 Déc 2017
Modifié(e) : Jan le 12 Déc 2017
This is a very strange example. Using strings to provide the function to be integrated is outdated for 15 years now. Appending [T, Y] as parameter is deprecated for the same time also - see http://www.mathworks.com/matlabcentral/answers/1971.
[T,Y] is not defined or used anywhere. So what it is purpose? All you need and use is [t,y].
Perhaps this helps:
t0 = 0;
tfinal = 20;
y0 = [500 10]';
tfinal = tfinal*(1+eps); % Are you sure that this is useful?
[t,y] = ode45(@MonodMod, [t0 tfinal], y0);
function yp = MonodMod(t, y)
k = -0.72901408450704225; % -0.56 -(0.024 / 1.42)
yp = [-(y(1) / (0.5 + y(1)) * y(1); ...
(y(1)*0.8 / (0.5 + y(1)) + k) * y(2)];

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by