ODE45 for Second Order
显示 更早的评论
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.
回答(1 个)
James Tursa
2018-6-6
编辑:James Tursa
2018-6-6
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 个评论
Shozeal
2018-6-6
James Tursa
2018-6-7
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
2018-6-14
James Tursa
2018-6-14
plot(t,y(:,1));
Shozeal
2018-6-14
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!