How to plot "f(x,y) = x^2 * y" function in matlab?
Afficher commentaires plus anciens
I am a beginner, so I am familiar with matlab. I am trying to plot a function: f(x, y) = x^2 * y, but it looks like something wrong. I am also trying another way but it looks different with a result I got from Google. Is there anybody have experience this problem, help me please?
The method I am trying is: x = rcost, y = rsint -> f(r, t) = r^2 * cos^2(t) * r * sin(t)
ra = linspace(-2.0, 2.0);
theta = linspace(-0.5*pi, 0.5*pi);
[TH, RA] = meshgrid(theta, ra);
F = RA.^3 * cos(TH) * cos(TH) * sin(TH);
surf(TH,RA,F);
shading interp;
3 commentaires
sixwwwwww
le 26 Oct 2013
Dear Minh, Can you share screen shot of expected out?
Image Analyst
le 27 Oct 2013
Modifié(e) : Image Analyst
le 27 Oct 2013
linspace takes 3 arguments, not 2. Anyway, see my answer below, which follows your original method, not the Google trig method.
the cyclist
le 27 Oct 2013
linspace() can accept two arguments. It will default to 100 generated points.
Réponse acceptée
Plus de réponses (1)
the cyclist
le 26 Oct 2013
I expect you are doing a matrix multiplication where you had actually wanted an element-by-element multiplication. Try this line instead:
F = RA.^3 .* cos(TH) .* cos(TH) .* sin(TH);
Notice how I modified your multiplications.
1 commentaire
Minh Phuoc
le 26 Oct 2013
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
