Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab:Evaluating ODE at Points

  1. May 21, 2008 #1
    Hello everyone.

    I have a second order ODE, which I reduced to two first order ODEs, and solved with ode45. Now I want to evaluate the solution and the derivative at certain points (specifically, I want to plot the Poincare section).

    So, what I did is this:

    Code (Text):
    >> sol=ode45(@...);
    >> xint=a:b;    
    >> [Sxint, Spxint]=deval(sol, xint);
    >> A=[Sxint, Spxint];
    >> plot(Sxint, Spxint,'o')
    xint is the points at which I want to evaluate the solution.
    Sxint is the value of the solution at the points xint.
    Spxint is the value of the derivative at those points.

    But this is clearly wrong. I know the solution should be periodic, but I get something random. I think it's the plotting I'm doing incorrectly. Any help appreciated.
  2. jcsd
  3. May 21, 2008 #2
    Ok, instead, I created a seperate M-file:

    Code (Text):
    hold on,
    for i=1:length(xint)
        plot(Sxint(:,i), Spxint(:,1),'.')
    Is this correct?
  4. May 22, 2008 #3
    Nevermind, I've figured it out, you can close the thread.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook