Second Order Differential Equations in MatLab

Click For Summary
SUMMARY

This discussion focuses on modeling a stiff second-order differential equation using MATLAB, specifically the equation y'' + (2/x)*y' = (0.7/x^2)*((y^(-1/2)) - (0.067)*(1-y)^(-1/2)). The user encountered an error related to an undefined input argument "x" in their function definition. The correct function syntax requires defining the parameters within the function before invoking ode15s. The solution involves restructuring the function definition to ensure all variables are properly initialized.

PREREQUISITES
  • Understanding of second-order differential equations
  • Familiarity with MATLAB syntax and functions
  • Knowledge of numerical methods for solving differential equations, specifically ode15s
  • Basic concepts of boundary value problems
NEXT STEPS
  • Review MATLAB function definitions and scope of variables
  • Learn about MATLAB's ode15s function for solving stiff differential equations
  • Explore boundary value problem techniques in MATLAB
  • Study singularities in differential equations and their implications on solutions
USEFUL FOR

This discussion is beneficial for MATLAB users, mathematicians, and engineers working with differential equations, particularly those dealing with stiff equations and boundary value problems.

nasko89
Messages
1
Reaction score
0
Hey guys, I am new to PF. I need to be able to model a stiff differential equation in MatLab. I haven't used MatLab before so I am not really sure how to set the function and boundary conditions for the equation:

y'' + (2/x)*Y' = (.7/x^2)*( (y^(-1/2)) - (.067)((1-y)^(-1/2) )

y(0)=0
y'(1)=1
The zero boundary is undefined and there is a lot of singularities in the solution itself.

So far I have:

function dy = f(x,y)
y = [1 1];
k = .7;
lambda = .67;
xspan = [0 10];
ic = [0 1];
dy=[y(2); (-2/x) * y(2) + (k/(x)^2)*( (y(1)^(-1/2)) - lambda*((1-y(1)))^(-1/2) )];
[x,y] = ode15s(@f,xspan,ic);
plot(x,y(:,1),'-o')

And I am getting a an error in the command console:

? Input argument "x" is undefined.

Error in ==> f at 7
dy=[y(2); (-2/x) * y(2) + (k/(x)^2)*( (y(1)^(-1/2)) -
lambda*((1-y(1)))^(-1/2) )];

I do not know where to go from here.
 
Physics news on Phys.org
Can someone help me out?You need to define the function for dy before calling it in ode15s. The syntax should be something like this: function dy = f(x,y) k = .7; lambda = .67; dy=[y(2); (-2/x) * y(2) + (k/(x)^2)*( (y(1)^(-1/2)) - lambda*((1-y(1)))^(-1/2) )];endxspan = [0 10];ic = [0 1];[x,y] = ode15s(@f,xspan,ic);plot(x,y(:,1),'-o')
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K