# 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

1 view (last 30 days)
cindyawati cindyawati on 26 May 2023
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) VBBV on 26 May 2023
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
cindyawati cindyawati on 26 May 2023
Thank you @VBBV It is work!

Torsten on 26 May 2023
Why do you use a method for ordinary differential equations to integrate a simple function of the independent variable ?
syms T
f = 1/(1+exp(-T));
F = int(f,0,T);
F = matlabFunction(F);
T = 0:0.25:10;
plot(T,F(T)) 