How to plot two exponential functions on Matlab?
古いコメントを表示
I need to plot the two exponential functions on same graph. Please help me to write code. Thanks in advance.
f(x) = exp(-(((x-2)/3)^2)/2)
g(x) = 1-exp(-(((x-2)/3)^2))
採用された回答
その他の回答 (1 件)
Hi @Amna Habib
Try this:
x = -10:0.01:12;
f = exp(-(((x-2)/3).^2)/2);
g = 1-exp(-(((x-2)/3).^2));
plot(x, f, x, g)
xlabel('x')
legend('f(x)', 'g(x)')
grid on

6 件のコメント
Amna Habib
2022 年 3 月 28 日
Sam Chak
2022 年 3 月 28 日
Hi @Amna Habib
First, we plot
to see how it looks like.
x = -10:0.01:12;
f = exp(-(((x-2)/3).^2)/2);
g = 1-exp(-(((x-2)/3).^2));
h = f.^2 + g.^2;
plot(x, f, x, g, x, h, 'linewidth', 1.5)

Mathematically speaking, there is only one point where
, and this point is at the center of the function, that is
, because the Gaussian distribution function will never truly reach zero, unless you consider the trivial solutions at
.
To show you this, type this:
index = find(h == 1);
x(index)
and it returns the value of 2.
Hence, when you asked about
, the answer is naturally all real values of x. But I guess this is probably not what you are looking for. If you want to find x when
is approaching 1, then try this:
index = find(h < 0.999);
x_min = x(min(index))
x_max = x(max(index))
x_min = -5.8800
x_max = 9.8800
Compare these values with the plot of
above, and decide if the results are satisfactory.
Amna Habib
2022 年 3 月 28 日
Amna Habib
2022 年 3 月 29 日
Torsten
2022 年 3 月 29 日
X = -12:0.01:12;
f = zeros(size(X));
g = zeros(size(X));
f(X<=0) = exp(-((X(X<=0)/3).^2)/2);
f(X>0) = exp(-((X(X>0)/2).^2)/2);
g(X<=0) = 1 - exp(-((X(X<=0)/3).^2));
g(X>0) = 1 - exp(-((X(X>0)/2).^2));
h = f.^2 + g.^2;
plot(X,[f;g;h],'linewidth',1.5)
Amna Habib
2022 年 3 月 30 日
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




