How do i input (-1/x) - (y^2/x^2) into Matlab?
Show older comments
So far i've tried these:
(-1./X) -(Y.^2 * X.^-2)
(-X.^-1) -(Y.^2 * X.^-2)
(-X.^-1) -(Y.^2 / X.^-2)
(-X.^-1) -((Y.^2). / X.^-2)
(-X.^-1) -((Y.^2). / (X.^-2)))
can someone tell me what i am doing wrong?
Answers (2)
Paul Graham
on 19 Feb 2017
1 vote
(-1./x) - (y.^2./x.^2)
Star Strider
on 19 Feb 2017
Use the original equation with element-wise operations (note the dot operator ‘.’ before the exponentiation and division operators):
Z = (-1./X) - (Y.^2./Y.^2);
See the documentation for Array vs. Matrix Operations for details. (You would also use the dot operator with the multiplication operator if you used it here: (.*).)
Then use the meshgrid function to create compatible matrices for your variables:
x = linspace(-5, 5,25);
y = linspace(-10, 10, 50);
[X,Y] = meshgrid(x,y);
Use the surf or mesh functions to plot it.
I leave the rest to you.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!