From: Mohd Ikmal Ismail on
Hi,

I have a question about this problem how to find acceleration.deval function can be used to get acceleration at specific time..but, if you want to find and plot acceleration response in time domain u need acceleration for some points in time domain..How to do that?Hopefully there is anyone can help.thanks

Ikmal

"Jacek Kierzenka" <Jacek.Kierzenka(a)mathworks.com> wrote in message <cvnvgj$jdm$1(a)fred.mathworks.com>...
> Andrew,
>
> You are right. For your problem,
> [T,Y] = ODE45(...)
> will only return y and y', (as Y(:,1) and Y(:,2)).
>
> The reason is precisely what you mention: The solver evaluates the
> derivative (i.e., computes y'') several times per integration step, at
> various time points and various approximations to the solution at those
> points. More over, some of these solver steps will not satisfy the error
> tolerances and will ultimately be rejected...
>
> In most cases, the simplest way is to call your derivative function outside
> of the solver, passing the computed values of [T,Y]. That would evaluate
> the problem (true) derivative on an approximate solution.
>
> These days, most ODE solvers produce continuous approximate solutions. If
> you are interested in the derivative of the _approximate_ solution (and you
> use MATLAB 7), here is the trick
>
> >> sol = ode45(@odefun,...)
>
> will return a structure describing the approximate solution. The solution
> (and its first derivative) can be evaluated at any point of your interval of
> integration by calling
>
> >> [y,yp] = deval(sol,t)
>
> Thus, for your problem yp(2) will be the derivative of y(2), i.e., it will
> approximate y''(t).
> Take a look at
> >> help deval
>
>
> Hope that helps,
> Jacek
>
>
> ---------------------------
>
> "Andrew" <haebum(a)hotmail.com> wrote in message
> news:eefd15c.1(a)webx.raydaftYaTP...
> > Thank you for your response.
> >
> > Well, I guess that, for the 2nd order ode, y = y1, y' = y2 and y'' =
> > y2', so that:
> >
> > function dy = odefunc(t,y,...)
> > ...
> > [y1'] = [0 1][y1]+[0]
> > [y2'] = [-k/m -c/m][y2]+[f(t)/m]
> >
> > (* matrix form; no actual code; dy = [y1'; y2'])
> > ...
> >
> > If I am wrong, please correct me. The problem of ode45 I have is that
> > it returns only time and the first and second order response, that
> > is:
> >
> > [t,y] = ode45(@odefunc,t,y,opt,...)
> >
> > where y = [y1 y2] and y1 = y and y2 = y'. I need to get y2' = y''. As
> > you said, @odefunc returns dy(2) = y'' to ode45 whenever it is
> > called, but ode45 does not return dy(2).
> >
> > I once used a global variable (ddy=y''=y2') inside @odefunc to store
> > ddy = dy(2), but the problem was the 4th order Runge-Kutta (like
> > ode45) calls @odefunc 4 times for each integration step. As the
> > result, returned ddy-vector was longer length than y and y'.
> >
> > Sorry for failing to explain my problem precisely before. Would you
> > let me know a good solution?
> >
> > Thanks,
> >
> > Andrew
> >
> > Viðarr wrote:
> >>
> >>
> >> You need to express the equation as a system matrix of the form:
> >>
> >> [x'(1)] [ n x n ] [ x(1) ] [ ]
> >> [ : ] = [ coeff ] [ : ] + [ ] f(t)
> >> [x'(n)] [ matrix ] [ x(n) ] [ ]
> >>
> >> noting that y" = y'(1) = y(2), substituting y(2) for y", and going
> >> from
> >> there. Most ODE textbooks describe this in detail, as does
> >> "Examples:
> >> Solving Explicit ODE Problems" in Matlab's "Help" documentation.
> >> (See: "ODE
> >> solvers" -> "calling".)
> >>
> >> Viðarr
> >>
> >> --------------------
> >>
> >> "Andrew Yun" <haebum(a)hotmail.com> wrote in message
> >> news:eefd15c.-1(a)webx.raydaftYaTP...
> >>>I am using matlab ode solvers (ode45, ode15s...) for a dynamic
> >>> (mechanical) system, such as:
> >>>
> >>> m*y'' + c*y' + k*y = f(t) or similar...
> >>>
> >>> where y = displacement
> >>> y' = velocity
> >>> y'' = acceleration
> >>>
> >>> Everything is okay with the ode solvers, but they give only
> > zero
> >> and
> >>> first order derivatives (y and y'). Is there any way I can
> > obtain
> >> y''
> >>> with matlab ode solver? I searched the bboard to find the
> > answer,
> >> and
> >>> it seems that using odeset('OutputFnc',@func) might be an
> > option.
> >> If
> >>> so, could someone explain it more detail?
> >>>
> >>> Many thanks,
> >>>
> >>> Andrew
> >>
> >>
>
>