필터 지우기
필터 지우기

Plot the function combining an exponential function and a step function

조회 수: 5 (최근 30일)
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개)

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 CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by