how to get a plot of second ODE

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 件のコメント

Jan
Jan 2021 年 12 月 13 日
編集済み: Jan 2021 年 12 月 13 日
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.

サインインしてコメントする。

 採用された回答

Jan
Jan 2021 年 12 月 13 日
編集済み: Jan 2021 年 12 月 13 日

0 投票

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.

1 件のコメント

lily
lily 2021 年 12 月 13 日
Thank you for the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2021 年 12 月 13 日

コメント済み:

2021 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by