how to get a plot of second ODE

1 visualizzazione (ultimi 30 giorni)
lily
lily il 13 Dic 2021
Commentato: lily il 13 Dic 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 Commento
Jan
Jan il 13 Dic 2021
Modificato: Jan il 13 Dic 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.

Accedi per commentare.

Risposta accettata

Jan
Jan il 13 Dic 2021
Modificato: Jan il 13 Dic 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.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by