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

  • Context: Graduate 
  • Thread starter Thread starter Void123
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion centers on solving the second-order differential equation (1/(x^2)) d/dx [(x^2)(dy/dx)] + y^n = 0 using MATLAB. The user implements the Euler method for numerical integration but encounters an issue where the graph window opens without displaying any plots for the specified equation. Other equations work correctly, indicating a potential problem with the specific parameters or functions defined in the MATLAB code. A suggestion is made to substitute x=exp(t) to simplify the equation for better handling.

PREREQUISITES
  • Understanding of second-order differential equations
  • Familiarity with MATLAB programming and syntax
  • Knowledge of numerical methods, specifically the Euler method
  • Basic concepts of plotting in MATLAB
NEXT STEPS
  • Investigate MATLAB's plotting functions to ensure correct graphical output
  • Learn about the implications of substituting variables in differential equations
  • Explore MATLAB's ode solvers, such as ode45, for solving differential equations
  • Review the stability and convergence of the Euler method in numerical analysis
USEFUL FOR

Mathematicians, engineers, and students working with differential equations and numerical methods in MATLAB, particularly those seeking to visualize solutions effectively.

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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
Replies
1
Views
2K
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
5
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K