How to use Runge-Kutta orde 4 in sigmoid equation. I want to plot sigmoid equation with Runge kutta orde 4th but my graph is linear. I need help
2 次查看(过去 30 天)
显示 更早的评论
This is my function
%This is my Runge Kutta for sigmoid equation
S=0;
for j = 1:length(t)-1
k1S = dt*fRK4S(S(j));
k2S = dt*fRK4S(S(j)+k1S/2);
k3S = dt*fRK4S(S(j)+k2S/2);
k4S = dt*fRK4S(S(j)+k3S);
S(j+1) = S(j)+1/6*(k1S+2*k2S+2*k3S+k4S);
end
plot (S)
0 个评论
采纳的回答
VBBV
2023-5-26
You need to pass both t & S parameters to function fRK4S according to Runge-Kutte 4th order scheme
%This is my Runge Kutta for sigmoid equation
S(1)= 1; dt = 0.5;
a = 0; b = 10;
t = 0:dt:10; N = 100;
h = (b-a)/N;
for j = 1:length(t)-1
k1S = fRK4S(t(j),S(j));
k2S = fRK4S(t(j)+h/2,S(j)+(h*k1S)/2);
k3S = fRK4S(t(j)+h/2,S(j)+(h*k2S)/2);
k4S = fRK4S(t(j)+h, S(j)+h*k3S);
S(j+1) = S(j)+(1/6)*(k1S+2*k2S+2*k3S+k4S);
end
plot(t,S); grid
function S = fRK4S(t,S)
S = S/(1+exp(-t));
end
更多回答(1 个)
Torsten
2023-5-26
Why do you use a method for ordinary differential equations to integrate a simple function of the independent variable ?
Use "integral" instead or
syms T
f = 1/(1+exp(-T));
F = int(f,0,T);
F = matlabFunction(F);
T = 0:0.25:10;
plot(T,F(T))
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!