- 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
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
August Lindberg
am 20 Nov. 2021
Kommentiert: RITWIK SINGH
am 9 Dez. 2021
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 Kommentare
Akzeptierte Antwort
Dave B
am 20 Nov. 2021
Bearbeitet: Dave B
am 20 Nov. 2021
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 Kommentare
RITWIK SINGH
am 9 Dez. 2021
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?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!