How to plot a two variable function with exponentials and cosine.

1 visualización (últimos 30 días)
EDIT: Sorry if i may seem clueless but my teacher literally uploaded this equation with a scenario of it being the powerloss equation for a laser beam, then he said plot the signal using matlab.
Hi I'm trying to plot a two variable function with exponentials and cosine. I am really rusty with matlab but I tried just about everything and I keep getting unspecific errors. I will atach my my teacher wanted us to plot.
Here is my code:
E(x,t)=150*exp(-0.03*x)*cos(3*10.^(-15)*(t)-10.^(7)*(x));
plot(E);

Respuesta aceptada

Star Strider
Star Strider el 4 de Sept. de 2020
I am not certain what you want.
Try tthis:
x = linspace(-pi, pi, 60); % Use Your Own Limits
t = linspace(0, 60, 50); % Use Your Own Limits
[X,T] = ndgrid(x,t);
E = @(x,t) 150*exp(-0.03*x) .* cos(3E-15.*t - 1E7.*x);
figure
plot(x,E(X,T))
grid
figure
plot(t,E(X,T))
grid
figure
surfc(X,T,E(X,T))
grid on
.
  2 comentarios
Seleste Mendoza
Seleste Mendoza el 4 de Sept. de 2020
I am honestly not sure what my teacher wants... he was very vauge about what he wanted. He just dropped the equation and said to plot it on matlab. Nut thank you for your help I will try this

Iniciar sesión para comentar.

Más respuestas (2)

David Hill
David Hill el 4 de Sept. de 2020
Editada: David Hill el 4 de Sept. de 2020
It is important to know what the ranges are for x and t. I guessed. You must do a plot3 or surf or some other 3d type of plot.
[x,t]=meshgrid(1e-8:1e-9:1e-7,1e14:1e13:1e15);
E=@(x,t)150*exp(-0.03*x).*cos(3*10^(-15)*(t)-10^(7)*(x));
surf(x,t,E(x,t));
  2 comentarios
David Hill
David Hill el 4 de Sept. de 2020
Editada: David Hill el 4 de Sept. de 2020
Provides more data with no edge color.
[x,t]=meshgrid(1e-9:1e-9:1e-6,1e13:1e12:1e16);
E=@(x,t)150*exp(-0.03*x).*cos(3*10^(-15)*(t)-10^(7)*(x));
a=surf(x,t,E(x,t));
a.EdgeColor = 'none';
Seleste Mendoza
Seleste Mendoza el 4 de Sept. de 2020
This makes alot of sense. Thank you. I will try this

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 4 de Sept. de 2020
You need to decide whether you are working symbolically or numerically. Your first line is not going to work unless you have defined
syms x t
in which case you are defining a symbolic function named E that expects two parameters. But plot() cannot be used with Symbolic functions: you would need fsurf()
If you are working numerically then you need to vectorize your code such as is shown by Dave Hill.
However where Star Strider and Dave showed creating numeric meshes, you could instead pass the function handle to fsurf along with the plot ranges and let it create values as needed.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by