Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Which is a better approach to solve the following set of equations?

Asked by Urvi on 3 Oct 2012

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 Comments

Urvi

Tags

Products

No products are associated with this question.

1 Answer

Answer by Babak on 3 Oct 2012

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 Comments

Urvi on 4 Oct 2012

This is relatively a simple set of equations as compared to my model equations. I want to enter the initial value of b,x,y at time t=0 and use this to solve for getting the respective values at time t+delta t...this new value will be used to calculate the values in the next time step.

Also, I want to fix delta t. What you suggested is the interval at which I want the results. I want to solve these equations simultaneously.

Babak on 4 Oct 2012

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.

Babak

Contact us