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.

Antworten (1)

James Tursa
James Tursa am 6 Jun. 2018
Bearbeitet: James Tursa am 6 Jun. 2018

1 Stimme

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 Kommentare

Shozeal
Shozeal am 6 Jun. 2018
What I meant by y(0) being a vector is that y(0) has a range of values from 0 to 2.5e-3 and also t varies from ( i.e t0 to tf) 0 to 8e-5. But y'(0) is just a number 100.
Yes, I made a mistake while typing the expression. f = @(t,y) [y(2);(A/R)*(1-(y(2)^2/c^2))^1.5];
James Tursa
James Tursa am 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
Shozeal am 14 Jun. 2018
Thank you, James. So I created a .m file and a function file to solve the equation. My issue now is the plot, it's plotting dy/dt and y against time but I just want to plot y against time.
[t,y]=ode45(@func,timespan,initial);
plot(y,t)
James Tursa
James Tursa am 14 Jun. 2018
plot(t,y(:,1));
Shozeal
Shozeal am 14 Jun. 2018
Exactly what I am looking for, thanks a lot.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 6 Jun. 2018

Kommentiert:

am 14 Jun. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by