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!
0 个评论
采纳的回答
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
2022-4-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!