Struggling to Solve 2nd Order ODE with Multiple Initial Values
I’m currently trying to solve a 2nd order ODE with dsolve and cannot get it to properly output a solution…
Here are my ODE, initial conditions, and code…
ODE:
Initial Conditions:
: Where
My code:
clear all;
syms R(r)
eqn = diff(R,2) == R-R^3-(1/r)*diff(R);
V = odeToVectorField(eqn)
M = matlabFunction(V,’vars’,{‘r’,’Y’})
interval = [0 20];
yInit = [2.2 2.2];
ySol = ode45(M,interval,yInit);
figure(2);
tValues = linspace(0,20,100);
yValues = deval(ySol,tValues,1);
plot(tValues,yValues)
When I run this I don’t get an error, but my yValues always have the first value equal to my initial condition and the rest are NaN’s.
My questions:
1: How do I specify that my initial conditions are R'(0)=0 and R(large-number)=0 within the syntax of ODE45?
2: Since I assume the 1/r in my ODE is the cause of the NaN’s, how do I get around this?
3: Is there a simpler way to solve this system?
Thanks in advance for your help.
-DavidI’m currently trying to solve a 2nd order ODE with dsolve and cannot get it to properly output a solution…
Here are my ODE, initial conditions, and code…
ODE:
Initial Conditions:
: Where
My code:
clear all;
syms R(r)
eqn = diff(R,2) == R-R^3-(1/r)*diff(R);
V = odeToVectorField(eqn)
M = matlabFunction(V,’vars’,{‘r’,’Y’})
interval = [0 20];
yInit = [2.2 2.2];
ySol = ode45(M,interval,yInit);
figure(2);
tValues = linspace(0,20,100);
yValues = deval(ySol,tValues,1);
plot(tValues,yValues)
When I run this I don’t get an error, but my yValues always have the first value equal to my initial condition and the rest are NaN’s.
My questions:
1: How do I specify that my initial conditions are R'(0)=0 and R(large-number)=0 within the syntax of ODE45?
2: Since I assume the 1/r in my ODE is the cause of the NaN’s, how do I get around this?
3: Is there a simpler way to solve this system?
Thanks in advance for your help.
-David I’m currently trying to solve a 2nd order ODE with dsolve and cannot get it to properly output a solution…
Here are my ODE, initial conditions, and code…
ODE:
Initial Conditions:
: Where
My code:
clear all;
syms R(r)
eqn = diff(R,2) == R-R^3-(1/r)*diff(R);
V = odeToVectorField(eqn)
M = matlabFunction(V,’vars’,{‘r’,’Y’})
interval = [0 20];
yInit = [2.2 2.2];
ySol = ode45(M,interval,yInit);
figure(2);
tValues = linspace(0,20,100);
yValues = deval(ySol,tValues,1);
plot(tValues,yValues)
When I run this I don’t get an error, but my yValues always have the first value equal to my initial condition and the rest are NaN’s.
My questions:
1: How do I specify that my initial conditions are R'(0)=0 and R(large-number)=0 within the syntax of ODE45?
2: Since I assume the 1/r in my ODE is the cause of the NaN’s, how do I get around this?
3: Is there a simpler way to solve this system?
Thanks in advance for your help.
-David differential equations, ode45 MATLAB Answers — New Questions