Plot the function combining an exponential function and a step function
13 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Riccardo Scorretti
on 10 Apr 2022
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');
More Answers (1)
Sam Chak
on 10 Apr 2022
Hi @Nick
Please check the piecewise function
if it is what you desire. Then, check the equation
and the plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/959105/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/959110/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/959115/image.png)
2 Comments
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!