- There's no .- in MATLAB, you use the dot to indicate you want a element-wise operation instead of a matrix operation, but for + and - there's only one option.
- exp is a function, so you can do exp(1)^n if you really want, but it's easier to just do exp(n)
- Inside your exp power you have 2Y, but you meant 2*Y.
Invalid use of operator while trying to plot surface
1 次查看(过去 30 天)
显示 更早的评论
I am a total rookie when it comes to MatLab so I got stuck right away when trying to plot a surface. I get the "invalid use of operator" error code when trying to write the expression for Z, which is supposed to look something like this: z=(4x^2+8xy-2y^2)e^{-(x^2+2y^2)}. MatLab seems to point out that the minus sign in front of the 2 is the issue. How should I code the expression?
>> x=linspace(-3,3);
y=linspace(-2,2);
[X,Y]=meshgrid(x,y);
Z=(4*X.^2+8*X.*Y.-2*Y.^2)*exp^-(X.^2+2Y.^2);
↑
Invalid use of operator.
Thanks in advance!
0 个评论
采纳的回答
Dave B
2021-11-20
编辑:Dave B
2021-11-20
A few issues:
x=linspace(-3,3);
y=linspace(-2,2);
[X,Y]=meshgrid(x,y);
Z=(4*X.^2+8*X.*Y-2*Y.^2)*exp(-X.^2+2*Y.^2)
Pro tip: break things up into small pieces...it's much easier to debug (and catch if you've not made the order of operations you intended!). For example:
a=4*X.^2;
b=8*X.*Y;
c=2*Y.^2;
d=-X.^2;
e=2*Y.^2;
Z2=(a+b-c)*exp(d+e);
4 个评论
RITWIK SINGH
2021-12-9
i have a similar issue in this line
EbN0Lin = 10.^(EbN0dB/10);
theoryBer_nRx1 = 0.5.(1-1(1+1./EbN0Lin).^(-0.5));
p = 1/2 - 1/2.(1+1./EbN0Lin).^(-1/2);
theoryBerMRC_Rx2 = p.^2.(1+2(1-p));
any idea how to fix?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!