Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Differential equation and ode45 or ode15i
Replies: 10   Last Post: Jan 28, 2014 3:14 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Torsten

Posts: 1,459
Registered: 11/8/10
Re: Differential equation and ode45 or ode15i
Posted: Jan 28, 2014 2:22 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"shatrah " <shatrah1978@gmail.com> wrote in message <lc63k7$dh3$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <lc5tqg$495$1@newscl01ah.mathworks.com>...
> > "shatrah " <shatrah1978@gmail.com> wrote in message <lc5sso$kdh$1@newscl01ah.mathworks.com>...
> > > "Torsten" wrote in message <lc5r64$o8h$1@newscl01ah.mathworks.com>...
> > > > "shatrah " <shatrah1978@gmail.com> wrote in message <lc5q4c$4a9$1@newscl01ah.mathworks.com>...
> > > > > "Torsten" wrote in message <lc5mi0$n5t$1@newscl01ah.mathworks.com>...
> > > > > > "shatrah " <shatrah1978@gmail.com> wrote in message <lc35in$d3g$1@newscl01ah.mathworks.com>...
> > > > > > > dq/dz=dy/dz+q
> > > > > > > dy/dz=z*y
> > > > > > > ds/dz=dy/dz+dq/dz
> > > > > > >
> > > > > > > y=10, dy/dz=0 for z=0
> > > > > > > z=15, dz/dz=0 for z=0
> > > > > > > q=11, dq/dz=0 for z=0
> > > > > > >
> > > > > > >
> > > > > > > 1- how can solve this problem ? using ode45 or ode15i
> > > > > > >
> > > > > > >
> > > > > > > if i need to use ode45 can make like this
> > > > > > >
> > > > > > > dy(1)=dy(2)+y(1)
> > > > > > > dy(2)=y(2)*z
> > > > > > > dy(3)=dy(2)+dy(1)
> > > > > > >
> > > > > > >
> > > > > > > as a function filw ?
> > > > > > >
> > > > > > > Thanks

> > > > > >
> > > > > > function dy = test(z,y)
> > > > > > dy = zeros(3,1); % a column vector
> > > > > > dy(1)=z*y(2)+y(1);
> > > > > > dy(2)=z*y(2);
> > > > > > dy(3)=2*z*y(2)+y(1);
> > > > > >
> > > > > > But I don't understand your initial conditions:
> > > > > > y=10, dy/dz=0 for z=0
> > > > > > z=15, dz/dz=0 for z=0
> > > > > > q=11, dq/dz=0 for z=0
> > > > > >
> > > > > > Best wishes
> > > > > > Torsten.

> > > > >
> > > > > Dont look at my initial conditions , its just example ,
> > > > > my question can put like this dy(1)=dy(2) ??
> > > > >

> > > >
> > > > Yes, you can. Just insert the expressions for the derivatives from the other equations.
> > > > dy(1)=dy(2)+y(1) can be written as dy(1)=z*y(2)+y(1) since dy(2)=z*y(2).
> > > > Likewise dy(3)=dy(2)+dy(1) can be written as dy(3)=2*z*y(2)+y(1) since
> > > > dy(2)=z*y(2) and dy(1)= z*y(2)+y(1).
> > > >
> > > > Best wishes
> > > > Torsten.

> > >
> > > on my expression i need to write dy(1)=dy(2)+y(1) Instead of dy(1)=z*y(2)+y(1) ? so i can do than without any problem or logic problems ?

> >
> > I don't understand what you are asking for.
> > If your equations read

> > > > > > > dq/dz=dy/dz+q
> > > > > > > dy/dz=z*y
> > > > > > > ds/dz=dy/dz+dq/dz,

> > write them as
> > dq/dz=z*y+q
> > dy/dz=z*y
> > ds/dz=z*y+z*y+q
> > and implement them as

> > > > > > function dy = test(z,y)
> > > > > > dy = zeros(3,1); % a column vector
> > > > > > dy(1)=z*y(2)+y(1);
> > > > > > dy(2)=z*y(2);
> > > > > > dy(3)=2*z*y(2)+y(1);

> > for ODE45.
> > If you want to stick to the formulation

> > > > > > > dq/dz=dy/dz+q
> > > > > > > dy/dz=z*y
> > > > > > > ds/dz=dy/dz+dq/dz,

> > rewrite the system as
> > > > > > > dq/dz-dy/dz=q
> > > > > > > dy/dz=z*y
> > > > > > > ds/dz-dy/dz-dq/dz=0

> > and define a mass-matrix different from the identity matrix for the ODE solvers.
> > Search for "mass matrix" under
> > http://www.mathworks.de/de/help/matlab/ref/ode45.html
> >
> > Best wishes
> > Torsten.
> >

>
> Thanks fo reply ....
> Please just answe this questin ( my clear one )
> Can I use this on matlab ode45 , dy(1)=dy(2)+d(3) ???? Or must left side contain only dy and right side don't contain dy ??? Clear question !!! Thanks


The form of the ODE systems allowed for all integrators except ODE15I is
M*dy/dt = f(t,y)
Thus the right-hand side of the system is _not_ allowed to contain derivatives of the solution variables. Thus, if you return your dy-vector, it must be made up only of the solution variables.
Nonetheless, if you can express the derivatives in term of the solution variables
_in advance_, you can of course use the derivatives on the right-hand side.

For your system, this would mean that your function routine could look like

function dy = test(z,y)
dy = zeros(3,1); % a column vector
dy(2)=z*y(2);
dy(1)=dy(2)+y(1);
dy(3)=dy(2)+dy(1);

Note that

function dy = test(z,y)
dy = zeros(3,1); % a column vector
dy(1)=dy(2)+y(1);
dy(2)=z*y(2);
dy(3)=dy(2)+dy(1);

would not be possible because dy(2) is not yet defined when you calculate dy(1).

Best wishes
Torsten.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.