Search code examples
matlabdifferential-equations

Why do these differential equations yield similar results?


I was wondering if there was some problem with my Matlab code for solving a 2nd order differential equation. The equation is y"+cy'+12.5y=2.5cos(wt). This is the code I was using:

function [ dydt ] = order2( t,y )

dydt = zeros(size(y));
c=2.5;
%c=0.25;
%c=0.025;

w=sqrt(12.5-(c^2/4)); 
a = 2.5; 
b = 12.5; 
r = 2.5*cos(w*t); 
dydt(1) = y(2);
dydt(2) = r -a*y(2) - b*y(1);

end

Code inputted into command window:

>>  tspan = [0 40];
y0 = [1,2];
[t,y]=ode45(@order2,tspan,y0);
plot(t,y(:,1))

The problem is, this code does seem to work (it outputs a graph), but when I use each of those c values, the graph it produces looks almost the same. I thought that there would be a significant difference between the graphs. Does it make sense for the results to be almost the same or is there something off with my code?


Solution

  • If you implement the equation correctly, so that indeed a=c and the numerical equation actually represents the resonance case, then you also get 3 different graphs. Below they are shown in one diagram. One can see how the saturation amplitude depends on the friction coefficient, low friction large amplitude and vv.

    diagram of resonance

    b = 12.5; 
    def derivs(y,t,c):
        w = (b-c**2/4)**0.5
        return [ y[1], 2.5*np.cos(w*t) - c*y[1] - b*y[0] ]
    
    tspan = np.linspace(0,20,501)
    cs = [2.5, 0.25, 0.025 ]
    sols = [ odeint(lambda y,t: derivs(y,t,c), [1.,2.], tspan) for c in cs]
    for c,sol in zip(cs, sols): plt.plot(tspan, sol[:,0], label="c=%6f"%c)
    plt.legend(loc="best");plt.show()