Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

(1/(x^2)) d/dx [(x^2)(dy/dx)] + y^n = 0

  1. Jul 26, 2010 #1
    I have the following second order differential equation:

    (1/(x^2)) d/dx [(x^2)(dy/dx)] + y^n = 0

    which I am trying to put into the following code [matlab] template:

    Code (Text):
    function euler2

    tspan(1)=0;tspan(2)=15;          % Interval on which to integrate
    t = tspan(1);                    % used for numerical solution
    u = 1;                % initial data for u=y and initializes do loop
    v = 0;                % initial data for v=y'and initializes do loop

    %%%%%%%%  main do loop for Euler Method %%%%%%%%
        for n=1:N
         f1      = feval(@rsu,t,u,v);
         f2      = feval(@rsv,t,u,v);
         u       = u+h*f1;
         v       = v+h*f2;
         t       = t+h;
         uout(n) = u;
         vout(n) = v;
         tt(n)   = t;
    %%%%%%%%  main do loop for Euler Method %%%%%%%%

    %%%%%%%%%%%% plotting details %%%%%%%%%%%%%%%
    hold on;
      plot(tt,uout,'b-','LineWidth',1.5);axis tight;

    %%%%%% function definitions %%%%%%%%%%%%%%%
    function p=p(t)           % defines function p(t)

    function q=q(t)           % defines function q(t)

    function g=g(t)         % defines forcing function

    function dudt=rsu(t,u,v)    % defines function for forward Euler
    function dvdt=rsv(t,u,v)    % defines function for forward Euler

    For some reason, when I put my equation in (of course for assumed values of 'n'), the graph window pops up but there is no plot on it.

    When I try other equations its works, but the one I want doesn't give me any graphical output.

    Does anybody have an idea of whats going on?
  2. jcsd
  3. Jul 27, 2010 #2
    Re: Ode

    Try substituting x=exp(t) to simplify the equation.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook