Matlab:Evaluating ODE at Points

  • Context: MATLAB 
  • Thread starter Thread starter qspeechc
  • Start date Start date
  • Tags Tags
    Ode Points
Click For Summary
SUMMARY

The discussion focuses on evaluating the solution and its derivative of a second-order ordinary differential equation (ODE) using MATLAB's ode45 function. The user initially attempted to plot the results using the deval function to interpolate the solution at specified points but encountered unexpected results. After further experimentation, the user created a loop to plot the points correctly, confirming that the periodic nature of the solution was preserved in the final output.

PREREQUISITES
  • Understanding of ordinary differential equations (ODEs)
  • Familiarity with MATLAB programming and syntax
  • Knowledge of MATLAB's ode45 function for numerical solutions
  • Experience with data visualization in MATLAB using the plot function
NEXT STEPS
  • Explore MATLAB's deval function for evaluating ODE solutions
  • Learn about creating custom plotting functions in MATLAB
  • Investigate periodic solutions of ODEs and their graphical representations
  • Study advanced MATLAB techniques for handling numerical data and visualizations
USEFUL FOR

Mathematics students, engineers, and researchers working with differential equations in MATLAB, particularly those interested in numerical methods and data visualization techniques.

qspeechc
Messages
839
Reaction score
15
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:
>> sol=ode45(@...);
>> xint=a:b;    
>> [Sxint, Spxint]=deval(sol, xint);
>> A=[Sxint, Spxint];
>> plot(Sxint, Spxint,'o')

Where:
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.
 
Physics news on Phys.org
Ok, instead, I created a separate M-file:

Code:
hold on,
for i=1:length(xint)
    plot(Sxint(:,i), Spxint(:,1),'.')
end

Is this correct?
 
Nevermind, I've figured it out, you can close the thread.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K