Which is a better approach to solve the following set of equations?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to understand a logic behind my system of equations. Hence, I am giving an example of the same. Suppose I have to solve the following set of equations :
k1=1;
k2=3;
b=10*sqrt(b)+1000*t;
x=y+b;
dy/dt=-k1*y+k2*x;
I want to solve these simultaneously. Please do not substitute x=y+b into dy/dt equation.
I know the initial conditions for b,y. How can I solve this system in order to find x,y and b? Can the solver use the initial value of b to solve for value of b in the next time step and use that to calculate dy/dt?
Also, I want my solver to have constant time step. ode45 is adaptive but I want to have a constant time step ( not time interval). How can I change that?
Thanks!
댓글 수: 0
답변 (1개)
Babak
2012년 10월 3일
In regards to the time step, you can use any ODE solver but determine the time step to be in the form of
linspace(0,100,51)
or
0:2:100
instead of
[0 100]
In regards to your problem:
You have only 1order differential equation with parameters coming from other equations that need to be solved before the ODE be integrated. So you need to solve those equations for b (and probably x) before you integrate the differential equation for y.
You can easily solve for b as a function of t manually from (b=10*sqrt(b)+1000*t) but it seems you don't want (or like) to do that.
You could also write a subroutine in your ODE's velocity function that uses (for example) fsolve to solve for the solution of b and x.
댓글 수: 2
Babak
2012년 10월 4일
I tried to tell you that b and x are not and cannot be a part the initial conditions.
Given t you can calculate b and given an initial condition for y like y(0) you can calculate x (from b and y) then you should integrate the differential equation for y.
So, Do not think that your equations are a set of coupled differential equations. It is one (1st order) differential equations coupled with some algebraic equations. So at any time step like t=t0 where you know y(t0) you can calculate the solution for the next time step by first solving for b, second solving for x and third integrating the differential equationa and solve for y.
Regarding the ODE solvers in MATLAB, all of them are variable step, but with the trick I told you in my answer above you can find the solutions at the time spans lineasly spaced. Here is another post saying this: http://www.mathworks.com/support/solutions/en/data/1-1TJ3GZ/
In Simulink on the other hand there is the possibility for integrating your equation with a fixed step solver. You can draw a Simulink model and go to the configurations parameters dialog box and set the solver be a fixed step and integrate and get the response in a scope or a matrix loaded in MATLAB workspace for example.
참고 항목
카테고리
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!