Problem with matlab
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comments
Titus Edelhofer
on 26 Jul 2011
I'd suggest to take a look at
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-
how-to-ask-a-question-on-answers-and-get-a-fast-answer
first ...
Arnaud Miege
on 26 Jul 2011
It would help if you posted the code for the function 'function'. BTW, it's not a very good idea to call a function 'function', as function is a reserved for defining, well, functions.
Jan
on 26 Jul 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.
Javier
on 27 Jul 2011
Answers (1)
Ivan van der Kroon
on 26 Jul 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 Comments
Javier
on 26 Jul 2011
Jan
on 26 Jul 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.
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!