Matlab:Evaluating ODE at Points

  • MATLAB
  • Thread starter qspeechc
  • Start date
  • Tags
    Ode Points
In summary, the conversation involved the speaker discussing their process of solving a second order ODE with ode45 and then attempting to evaluate the solution and derivative at certain points using deval. However, their initial plotting method did not produce the expected periodic solution, so they created a separate M-file to plot the solution correctly. The issue was resolved and the conversation concluded.
  • #1
844
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
  • #2
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?
 
  • #3
Nevermind, I've figured it out, you can close the thread.
 

1. What is Matlab and how is it used for evaluating ODE at points?

Matlab is a programming language and environment commonly used in scientific and engineering fields. It has a built-in function called "ode45" that can numerically solve ordinary differential equations (ODEs) and evaluate them at specified points.

2. How do I specify the ODE and the points for evaluation in Matlab?

To specify the ODE, you need to create a function in Matlab that describes the derivatives of the dependent variables in terms of the independent variable. The points for evaluation can be specified as a vector of values for the independent variable.

3. Can Matlab handle systems of ODEs?

Yes, Matlab's "ode45" function can handle systems of ODEs by creating a function that describes the derivatives of all the dependent variables in terms of the independent variable.

4. How accurate is Matlab in evaluating ODEs at points?

Matlab's "ode45" function is a reliable and accurate method for evaluating ODEs at points. It uses a variable-step size algorithm that adjusts the step size to maintain a specified level of error.

5. Are there any limitations to using Matlab for evaluating ODEs at points?

One limitation of Matlab's "ode45" function is that it cannot handle stiff ODEs, which are equations that contain very large or very small terms. In these cases, other methods may need to be used for accurate evaluation.

Suggested for: Matlab:Evaluating ODE at Points

Replies
10
Views
2K
Replies
4
Views
841
Replies
6
Views
2K
Replies
4
Views
2K
Replies
3
Views
1K
Replies
14
Views
2K
Back
Top