How does evaluation of a function for each x and y coordinate in a matrix work?
Mostra commenti meno recenti
I am trying to solve a problem for one of my classes. I tried a few different codes based on ones the professor provided and that I found online, but I can't get anything to work. I found this code on here and it works to give a 3d plot of the function f(x,y)=x^2*y. However, if I change the "*" to a "-" or "+" and change nothing else, the code no longer works. Why is that? (The problem I am trying to solve is f(x,y)=(y-C)(3x^2-y^2) where C is a constant found earlier in the code, I'm not having an issue with that part)
x = linspace(-2.0, 2.0, 50);
y = linspace(-2.0, 2.0, 50);
[xm, ym] = meshgrid(x, y);
fxy = xm.^2 .* ym;
surf(fxy);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
6 Commenti
Thomas Ward
il 31 Mar 2018
per isakson
il 31 Mar 2018
- "if I change the "*" to a "-" or "+" and change nothing else, the code no longer works" I change .* to + and it works just fine on R2016a. See Array vs. Matrix Operations
- "the code no longer works" more details please!
Thomas Ward
il 31 Mar 2018
Thomas Ward
il 31 Mar 2018
per isakson
il 31 Mar 2018
Modificato: per isakson
il 31 Mar 2018
- "love to know what math it is doing behind the scenes" Did you use the link I provided?
- "Unexpected MATLAB operator" .+ is not a Matlab operator, but .* is. See MATLAB Operators and Special Characters.
Thomas Ward
il 31 Mar 2018
Risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!