how to get a plot of second ODE

5 Ansichten (letzte 30 Tage)
lily
lily am 13 Dez. 2021
Kommentiert: lily am 13 Dez. 2021
I'm trying to solve a second order ODE and plot it, when I use rk4 method it gives me an arry of yp = NaN and this message is shown : " warning: opengl_renderer: data values greater than float capacity. (1) Scale data, or (2) Use gnuplot"
I'm not able to detect the error in the code. I tried to use ode45 it resulted in the same message.
code:
function trying
clear,clc,clf;
tspan = [0 50]; y0 = [0; 0.1];
step=0.2;
[t, y]=rk4(@f,tspan,y0,step)
plot(t,y)
end
function yp=f(t,y)
yp=zeros(2,1);
j = 6.5*10^-5;
yp(1)=y(2);
yp(2)= y(1) / (t.*j) - (y(1)/(t.^2 .*j)) - (3.*y(2)./t)
end
  1 Kommentar
Jan
Jan am 13 Dez. 2021
Bearbeitet: Jan am 13 Dez. 2021
If gnuplot is suggested, this is not Matlab, but Octave. Please remember, that this is a Matlab forum.
rk4() is not a function of Matlab.
A clear on top of a function is a complete waste of time.
6.5*10^-5 is an expensive power operation, while 6.5e-5 is a cheap constant.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 13 Dez. 2021
Bearbeitet: Jan am 13 Dez. 2021
The interval is: tspan = [0 50]
In the first step you evaluate:
yp(2)= y(1) / (t.*j) - (y(1)/(t.^2 .*j)) - (3.*y(2)./t)
for t == 0. Then y(2) is NaN, because you divide by 0, and so are all folloing values also.
The function to be integrated is not defined on the initial time point.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by