Creating a simple plot

2 次查看(过去 30 天)
Vaultec
Vaultec 2014-10-1
Im trying to plot y=x*e^(-x^2) where the range of x is from -3,3
Ive tried running
x = -3:3; y = x*exp(-x.^2); plot (x, y) however i keep getting the error Inner matrix dimensions must agree. Not quite sure what that means

采纳的回答

Rick Rosson
Rick Rosson 2014-10-1
编辑:Rick Rosson 2014-10-1
Use .* instead of * here:
y = x.*exp(-x.^2);
Also, you will want higher resolution:
x = -3:0.01:3;

更多回答(2 个)

Michael Haderlein
Michael Haderlein 2014-10-1
You need element-wise multiplication:
x = -3:3;
y = x.*exp(-x.^2); %<-- here, I added the point
plot (x, y)

Vaultec
Vaultec 2014-10-1
ok thanks worked out perfectly

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by