How can I plot ln(1-x)/x using colon operator?

1 回表示 (過去 30 日間)
emma
emma 2021 年 2 月 27 日
コメント済み: emma 2021 年 2 月 27 日
I am trying to plot f(x)=ln(1-x)/x for -10^(-15)<=x<=10^(-15) but when I run the program it says "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-300." How can I alter my code so that it properly plots the function?
My code:
x = linspace(-10^(-15),10^(-15),300);
f = zeros(1,300);
for i = 1:300
f(:,i) = log((1-x(:,i))) ./ x;
end
f;
figure;
plot(x,f);
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 27 日
x = linspace(-10^(-15),10^(-15),300);
f=log(1-x)./x;
plot(x,f);
emma
emma 2021 年 2 月 27 日
Ah I was definitely overthinking the problem. Thank you for your timely help Kalyan!

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

採用された回答

Matt J
Matt J 2021 年 2 月 27 日
x = linspace(-10^(-15),10^(-15),300);
f = log(1-x)./x;
plot(x,f)
  1 件のコメント
emma
emma 2021 年 2 月 27 日
Thank you for the easy fix, and for showing the graph!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by