Solving the Duffing Equation with ODE45

  • MATLAB
  • Thread starter member 428835
  • Start date
  • Tags
    Ode45
In summary, the conversation is about trying to replicate a phase portrait of the Duffing equation found on a Wikipedia page. The speaker shares their code and the function they are using, but they are not getting the expected result. They realize that the initial conditions used in the Wikipedia page must be from a longer time out, not t=0 as shown in their code.
  • #1
member 428835
Hi PF

I am trying to replicate the phase portrait at the bottom right of this page: https://en.wikipedia.org/wiki/Duffing_equation

What I have is this:
Code:
global delta alpha beta gamma OMEG
delta   = 0.3;  % DAMPING
alpha   = -1;   % STIFFNESS
beta    = 1;    % RESTORATION NONLINEARITY
OMEG    = 1.2;  % DRIVING FORCE ANGULAR FREQ
gamma   = 0.2;  % FORCING

Fs = 100;       % Sampling frequency                    
T  = 1/Fs;      % Sampling period       
L  = 10000;     % Length of signal

[t, x]  = ode45(@duffing,(0:L-1)*T,[0 1]);

[~, idx] = min( abs( t-OMEG/(2*pi)*38 ) );

plot(x(1:idx,2),x(1:idx,1))
title('phase space')
xlabel('position')
ylabel('velocity')

and the function ode45 calls is

Code:
function xdot = duffing(t,x)
global delta alpha beta gamma OMEG
xdot(1) = -delta*x(1) - alpha*x(2) - beta*x(2)^3 + gamma*cos(OMEG*t);
xdot(2) = x(1);
xdot    = xdot';
end

For these parameter values I should get a cyclic phase portrait, but I don't. Can you see why?
 
Physics news on Phys.org
  • #2
Sheesh don't know how to delete this but I just realized they must be going from a long time out, not t=0 as shown, since their IC doesn't align to the phase portrait.
 

FAQ: Solving the Duffing Equation with ODE45

1. What is the Duffing Equation?

The Duffing Equation is a non-linear second-order differential equation that describes the motion of a damped oscillator subjected to an external force. It is commonly used in mathematical modeling and has applications in various fields such as physics, engineering, and biology.

2. What is ODE45?

ODE45 is a numerical method for solving ordinary differential equations (ODEs) of first-order. It is a Runge-Kutta algorithm that uses a fourth and fifth-order approximation to find the solution to the initial value problem. It is commonly used in scientific computing and is efficient for solving stiff systems of equations.

3. How is ODE45 used to solve the Duffing Equation?

To solve the Duffing Equation with ODE45, the equation is first transformed into a system of first-order equations. ODE45 then uses its adaptive time-stepping algorithm to numerically integrate the equations and find the solution. The user can specify the initial conditions and parameters to customize the solution.

4. What are the advantages of using ODE45 to solve the Duffing Equation?

ODE45 is a highly accurate and efficient method for solving differential equations, including the Duffing Equation. It allows for the solution of complex systems with multiple variables and parameters. Additionally, its adaptive time-stepping feature ensures that the solution is accurate and efficient.

5. Are there any limitations to using ODE45 for solving the Duffing Equation?

While ODE45 is a powerful tool for solving differential equations, it may not be suitable for all types of problems. It may encounter difficulties when solving highly oscillatory or stiff problems, and the user needs to ensure that the solution is stable. Additionally, ODE45 is a numerical method, so the solution may not be exact and may require further analysis and verification.

Similar threads

Replies
8
Views
702
Replies
5
Views
2K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top