Plot the function combining an exponential function and a step function

1 回表示 (過去 30 日間)
Nick
Nick 2022 年 4 月 10 日
コメント済み: Sam Chak 2022 年 4 月 10 日
I have a funtion involving exponential functions and one exponent is a step function of x.
The plot I need is y vs x,
y=(e^(2t)-1)*e^(-2.5x) ,
and t is a step function of x
where t=x for x<10
t=10 for x>=10
Please help me to plot such a function in xy space.
syms x ;
t =piecewise(x<10,x,x>=10,10);
y=(exp(2*t)-1)*exp(-2.5*x);
fplot(y)
The curve I got from the code above is clearly not correct. Could anyone tell me what is wrong and how to fix it? Thanks!

採用された回答

Riccardo Scorretti
Riccardo Scorretti 2022 年 4 月 10 日
Hi Nick,
Your program seems correct. Perhaps you need to adapt the range over which the graphic is plotted (the default range is [-5 5]). For instance, in the range [0 20] one obtains:
syms x
t = piecewise(x<10, x, x>=10, 10);
y = (exp(2*t)-1) * exp(-2.5*x);
fplot(y, [0 20], 'LineWidth', 2); % Plot between [0 20]
grid on ; xlabel('x') ; hold on ; drawnow
Let's check it by removing the function t and plotting separately on [0 10] and [10 20]:
y = (exp(2*x)-1) * exp(-2.5*x);
fplot(y, [0 10], 'Color', 'r');
y = (exp(2*10)-1) * exp(-2.5*x);
fplot(y, [10 20], 'Color', 'r');
grid on ; xlabel('x');
  1 件のコメント
Nick
Nick 2022 年 4 月 10 日
Thanks Riccardo! This is exactly what I need.

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

その他の回答 (1 件)

Sam Chak
Sam Chak 2022 年 4 月 10 日
Please check the piecewise function if it is what you desire. Then, check the equation and the plot.
subplot(2, 1, 1)
fplot(@(x) min(x,10), [-1 15])
grid on
xlabel('x')
ylabel('t')
title('Function t(x)')
subplot(2, 1, 2)
fplot(@(x) (exp(2*min(x, 10))-1).*exp(-2.5*x), [-1 15])
grid on
xlabel('x')
ylabel('y')
title('Function y(x)')
Result
  2 件のコメント
Nick
Nick 2022 年 4 月 10 日
Thank you Sam! This helps me a lot and now I know how subplot works.
Sam Chak
Sam Chak 2022 年 4 月 10 日
Don't mention it. There are many tricks and tips you can learn along.

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

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by