Search code examples
matlabnumerical-methodsdifferential-equationsscilab

Solving a non-linear second order differential equation on Scilab?


I need to solve the following

-cos(y)y''+sin(y)y'^2+sin(y)=0, y'(0)=y'(1)=0, such that y=y(t)

I find it hard to solve because of the term y'^2 and also the boundary conditions.


Solution

  • Here is the Scilab code for your bvp

    -cos(y)y''+sin(y)y'^2+sin(y)=0, y'(0)=y'(1)=0, y(0)=0, y(1)=1.5

    but with different boundary condition not giving the trivial solution. You have first to write y'' as a function of y and y'. The function fsub computes y'' as a function of u=[y,y']

    function ysecond=fsub(x,u)
        y=u(1);
        yprime=u(2);
        ysecond = sin(y)/cos(y)*(1+yprime^2);
    end
    
    function g=gsub(i, u),
        y=u(1);    
        select i
          case 1 then  // x=zeta(1)=0
            g = y // y(0)=0
          case 2 then // x=zeta(2)=1
            g = y-1.5 // y(1)=1.5
        end
    end
    
    N=1;
    m=2;
    x_low=0
    x_up=1;
    xpoints=linspace(0,1,100);
    zeta=[0,1];
    
    
    u = bvodeS(xpoints,m,N,x_low,x_up,fsub,gsub,zeta)
    plot(xpoints,u(1,:))
    

    enter image description here