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

2 ビュー (過去 30 日間)
Seleste Mendoza
Seleste Mendoza 2020 年 9 月 4 日
編集済み: David Hill 2020 年 9 月 4 日
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);

採用された回答

Star Strider
Star Strider 2020 年 9 月 4 日
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 件のコメント
Seleste Mendoza
Seleste Mendoza 2020 年 9 月 4 日
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
Star Strider
Star Strider 2020 年 9 月 4 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (2 件)

David Hill
David Hill 2020 年 9 月 4 日
編集済み: David Hill 2020 年 9 月 4 日
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 件のコメント
David Hill
David Hill 2020 年 9 月 4 日
編集済み: David Hill 2020 年 9 月 4 日
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 2020 年 9 月 4 日
This makes alot of sense. Thank you. I will try this

サインインしてコメントする。


Walter Roberson
Walter Roberson 2020 年 9 月 4 日
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.
  1 件のコメント
Seleste Mendoza
Seleste Mendoza 2020 年 9 月 4 日
Thank you sooo much for the help. I will try that

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by