How to plot two exponential functions on Matlab?
41 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Amna Habib
el 28 de Mzo. de 2022
Comentada: Amna Habib
el 30 de Mzo. de 2022
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))
0 comentarios
Respuesta aceptada
Star Strider
el 28 de Mzo. de 2022
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 comentarios
Más respuestas (1)
Sam Chak
el 28 de Mzo. de 2022
Editada: Sam Chak
el 28 de Mzo. de 2022
Hi @Amna Habib
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/944044/image.png)
6 comentarios
Torsten
el 29 de Mzo. de 2022
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)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!