Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Problem with matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, can anyone help me with the following problem matlab:
I have the equation: dy/dt=((-m/0.6)*(y/(23500+y))*X)+((1/10)*(47806-y))
Where m and X have a specific value for each time If t=45 --> m=6607 --> X=0,17 If t=47--> m=6407 --> X=0,19 t=49--> m=6483 --> X=0,19 . . . If t=84--> m=6367--> X=0,19
y(45)=20000
I need to get matlab values of "y" for each time through a ode45: [t, y] = ode45 ('function', [45.84], 20000);
But the program always ends giving error, If anyone knows how to solve the problem, please I need to solve it urgent.
Thank
4 commentaires
Jan
le 26 Juil 2011
Please post the complete error message instead of just just mentioning, that there is an error. The message contain important information for solving the problem.
Réponses (1)
Ivan van der Kroon
le 26 Juil 2011
Your function should assign values to m and X depending on the value of t. Note that t in the solver can take any value in your interval hence you should specify the function in a continuous sense.
For instance, if you specified them with a if-statement like
if t==47,
elseif t==47,
end
it will not work as you did not specify the values in between. I would suggest defining the function your ode calls like this:
function dy=rhs(t,y)
m=funm(t);
X=funX(t);
dy=((-m/0.6)*(y/(23500+y))*X)+((1/10)*(47806-y));
end
And make two more functions funm and funX. I guess it gives you more overview in this way. If these functions are not continuous, you can make them so by interp1 (which even allows you to make them like a step function).
2 commentaires
Jan
le 26 Juil 2011
@Javier: Strange question. If your function funm and funX use INTERP1, INTERP1 is used, otherwise it is not used. It's your decision.
@Ivan: This method will not produce an accurate integration. The stepsize control and integration scheme of ODE45 will fail tremendously if the integrated function is not smooth. Imagine a step from 46.99 to 47.01, when the parameters change at 47.0: The intermediate ODE evaluations use different parameters and if the step if rejected the new stepsize is calculated based on the evaluated trajectory. This leads to unpredictable results. It is very important for intergration not to insert any discontinuities in the integrand: No IF, no MIN or MAX, no CLOCK or other external dependencies.
If the integrand is discontinuous, use events to separate the different intervals. See the documentation of ODE45.
Cette question est clôturée.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!