필터 지우기
필터 지우기

How to plot two exponential functions on Matlab?

조회 수: 24 (최근 30일)
Amna Habib
Amna Habib 2022년 3월 28일
댓글: Amna Habib 2022년 3월 30일
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))

채택된 답변

Star Strider
Star Strider 2022년 3월 28일
Another approach —
x = linspace(0, 10);
f = @(x) exp(-(((x-2)/3).^2)/2);
g = @(x) 1-exp(-(((x-2)/3).^2));
figure
plot(x, [f(x); g(x)])
grid
legend('f(x)','g(x)', 'Location','best')
.
  댓글 수: 8
Amna Habib
Amna Habib 2022년 3월 29일
Very Nice @Star Strider!
Thanks a lot for sharing your knowledge!
I really apprecciate your effort.
Star Strider
Star Strider 2022년 3월 29일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sam Chak
Sam Chak 2022년 3월 28일
편집: Sam Chak 2022년 3월 28일
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
Torsten
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
Amna Habib 2022년 3월 30일
Thanks a lot @Torsten!
I appreciate your effort!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by