Second Order Differential Equations in MatLab

In summary, to model a stiff differential equation in MatLab, you need to define the function for dy and set the boundary conditions before calling it in ode15s. The syntax for defining the function should include the variables x and y, and the boundary conditions should be set using the xspan and ic variables. Don't forget to plot the solution using the plot() function.
  • #1
nasko89
1
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
  • #2
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')
 

Related to Second Order Differential Equations in MatLab

1. What is a second order differential equation?

A second order differential equation is a mathematical equation that relates the second derivative of a function to the function itself. It is commonly used to model physical phenomena that involve acceleration or change over time.

2. How do you solve second order differential equations in MatLab?

To solve a second order differential equation in MatLab, you can use the built-in function "ode45" or "ode15s". These functions use numerical methods to approximate the solution of the equation. Alternatively, you can also use the symbolic math toolbox in MatLab to find an exact solution.

3. What is the difference between initial value and boundary value problems for second order differential equations?

An initial value problem for a second order differential equation is one where the values of the function and its first derivative are known at a single point, while a boundary value problem is one where the values of the function are known at two or more points. In MatLab, initial value problems are solved using the "ode45" or "ode15s" function, while boundary value problems are solved using the "bvp4c" function.

4. Can MatLab solve second order differential equations with variable coefficients?

Yes, MatLab can solve second order differential equations with variable coefficients. You can define the coefficients as a function of the independent variable in the equation, and MatLab will use the values of these coefficients at each step of the numerical solution.

5. How do you plot the solution of a second order differential equation in MatLab?

To plot the solution of a second order differential equation in MatLab, you can use the "plot" function after solving the equation using "ode45" or "ode15s". You can also use the "fplot" function to plot the solution over a specific range of the independent variable.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
258
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
219
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
676
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top