ODE45 for Second Order
Show older comments
I have this second order ODE I am trying to solve w.r.t t (i.e d^2y/dt^2)
y'' = A/R[1-(1/c^2*(y')^2)]^1.5.
The initial value of y ( i.e y(0)) is a vector and y'(0) is a constant. Quantities A, R, and c are constants. I reduced it to a first order ODE as
y(1)' = A/R[1-(1/c^2*(y(1))^2)]^1.5
where y(1) = y' and wrote the script below:
A = 1.345e+8;
y0 = [0:10:2.5e-3];
y(1) = 2.5e-3;
c = 3e+4;
f = @(t,y) [y(2);((A/y)*(1-(y(1)/c^2)))];
tSpan = [0:10:50];
[t,y] = ode23(f,tSpan,y0)
but I keep getting an error. Please, what I did wrong? Thanks.
Answers (1)
James Tursa
on 6 Jun 2018
Edited: James Tursa
on 6 Jun 2018
Based on your description, I would have expected something more like this for the derivative:
R = 2.5e-3;
f = @(t,y) [y(2);(A/R)*(1-(y(2)^2/c^2))^1.5];
That being said, I don't follow what you mean by "y is a vector" and this initial condition:
y0 = [0:10:2.5e-3] <-- the stepping and final value don't make sense
Do you mean you want to solve this ODE independently for several different starting conditions?
5 Comments
Shozeal
on 6 Jun 2018
James Tursa
on 7 Jun 2018
Try y0 = [0;100] to get one of the solutions. To get other solutions replace y0(1) with another number and make another run.
Shozeal
on 14 Jun 2018
James Tursa
on 14 Jun 2018
plot(t,y(:,1));
Shozeal
on 14 Jun 2018
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!