I get error when I try to plot sigmoid function

3 ビュー (過去 30 日間)
cindyawati cindyawati
cindyawati cindyawati 2023 年 5 月 9 日
コメント済み: Sam Chak 2023 年 5 月 10 日
I try to plot equation with sigmoid function, but i get error
M1(1)=0;
t(1)=0;
h=0.01;
dt=-30:h:30;
t=zeros(length(dt),1);
M1=zeros(length(dt),1);
for i= 1:length(t)
t(i+1)=t(i)+dt;
M1(i+1)=M1(i)+1./(1+exp(-dt));
end
Unable to perform assignment because the left and right sides have a different number of elements.
plot(t,M1);

採用された回答

Star Strider
Star Strider 2023 年 5 月 9 日
Subscript ‘dt’. However the loop is not necessary and does not appear to plot the desired function —
M1(1)=0;
t(1)=0;
h=0.01;
dt=-30:h:30;
t=zeros(length(dt),1);
M1=zeros(length(dt),1);
for i= 1:length(t)
t(i+1)=t(i)+dt(i);
M1(i+1)=M1(i)+1./(1+exp(-dt(i)));
end
plot(t,M1);
Mv = 1./(1+exp(-dt));
figure
plot(dt,Mv)
The second plot may be what you want.
.

その他の回答 (2 件)

Sam Chak
Sam Chak 2023 年 5 月 9 日
A pure sigmoidal logistic function looks like this
x = linspace(-10, 10, 20001);
S = 1./(1 + exp(-x));
figure(1)
plot(x, S), grid on
title('Sigmoidal Logistic function')
xlabel('x')
But yours looks like the ReLU-like (rectified linear unit) activation function due to the Iterative addition of M1(i). Can you clarify the type of sigmoid function that you are looking for?
M1(1) = 0;
t(1) = 0;
h = 0.01;
dt = -30:h:30;
t = zeros(length(dt), 1);
M1 = zeros(length(dt), 1);
for i= 1:length(t)
t(i+1) = t(i) + dt(i);
M1(i+1) = M1(i) + 1./(1+exp(-dt(i)));
end
figure(2)
plot(dt, M1(2:end)), grid on
title('ReLU-like function')
xlabel('dt')
  3 件のコメント
cindyawati cindyawati
cindyawati cindyawati 2023 年 5 月 9 日
M1 (i) have the form empty array because M1(i) must repeated by time
Sam Chak
Sam Chak 2023 年 5 月 10 日
You're welcome, @cindyawati cindyawati. Thanks for your clarification.

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


Walter Roberson
Walter Roberson 2023 年 5 月 9 日
dt=-30:h:30;
dt is a vector
t(i+1)=t(i)+dt;
t(i) is a scalar. Add the complete vector dt and you will get a vector. But you cannot store a vector in the scalar location t(i+1)
  4 件のコメント
cindyawati cindyawati
cindyawati cindyawati 2023 年 5 月 9 日
t mean for time
Walter Roberson
Walter Roberson 2023 年 5 月 9 日
Like @Star Strider showed,
t(i+1)=t(i)+dt(i);

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by