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

  • Thread starter Thread starter Void123
  • Start date Start date
Void123
Messages
138
Reaction score
0
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:
function euler2

tspan(1)=0;tspan(2)=15;          % Interval on which to integrate
h=.01;N=round((tspan(2)-tspan(1))/h);
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;
    end
%%%%%%%%  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)
p=t;

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

function g=g(t)         % defines forcing function 
g=cos(t);

function dudt=rsu(t,u,v)    % defines function for forward Euler
dudt=v;
function dvdt=rsv(t,u,v)    % defines function for forward Euler
dvdt=g(t)-p(t)*v-q(t)*u;

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 what's going on?
 
Physics news on Phys.org


Try substituting x=exp(t) to simplify the equation.
 
Back
Top