how to use ode45 and another function like ode23 or any function to solve one system?
1 次查看(过去 30 天)
显示 更早的评论
I have system like
dot_x1= x1+x2;
dot_x2= x1^2-x3;
dot_x3= x1-2x1-3x3;
I want to solve the first ODE using ode45, and the remain two function using another function.
in other word how to currently import or export variable?
for example
the first function (has to be solved by ode45)
function [x_dot] = derivatives(t, x)
dot_x= x1+x2;
%%%%%%%%%%%%
the second one (has to be solved by another function)
function [x_dot] = derivatives(t, x)
dot_x(1)= x1^2-x3;
dot_x(2)= x1-2x1-3x3;
x_dot=x_dot';
the two function have variable from the other
2 个评论
Roger Stafford
2016-6-15
The 'ode' functions aren't set up to do that sort of thing. Your first equation involves x2 and therefore the second equation with dx2/dt must be a part of that same computation process. There is no avoiding it. Be content with using a single ode function to handle all three equations simultaneously.
回答(1 个)
Jan
2017-12-29
编辑:Jan
2017-12-29
The question is old: 14 Jun 2016, but maybe other readers will find it.
This cannot work. The system of ODEs must be solves simultaneously using either ode45 or another integrator. It is not meaningful to solve them separately and it would not be an advantage in any way. The different integrators would use different step sizes and a "magic" method to combine different integration schemes would increase the number of function evaluations.
Imagine that dot_x1 is constant and x1 is a straight line in consequence. Then ode45 could solve the complete integration in one step (assuming that it is not impeded by a maximum step size). But for dot_x2 and dot_x3 the value of x1 is required for the different time points inside the interval. Then ode45 would be forced to calculate the intermediate values also, and this will increase the number of function evaluations and the accumulated rounding errors. In consequence the final result will take more time and be less accurate than running the complete integration with a tool, which considers the actual stiffness or whatever detail of the other components of the derivative.
The problems gets worse considering, that dot_x1 requires the value of x2 also.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!