Prev: plsregress constraint
Next: Problems
From: Nikolas tuc on 17 Dec 2009 13:02 Hi there, I would like to ask you how can I plot a the following surface: x = linspace(-1, 1, 50); y = linspace(-1, 1, 50); z = (x.^2 + 2*y.^2); figure(1), surf([x' y' z']) The results that i get are not the expected ones. I would really appreciate any help of you Thank you NM
From: Pekka Kumpulainen on 17 Dec 2009 13:15 "Nikolas tuc" <nmihailidis(a)gmail.com> wrote in message <hgdrmv$5ov$1(a)fred.mathworks.com>... > Hi there, > > I would like to ask you how can I plot a the following surface: > > x = linspace(-1, 1, 50); > y = linspace(-1, 1, 50); > z = (x.^2 + 2*y.^2); > > figure(1), surf([x' y' z']) > > The results that i get are not the expected ones. > > I would really appreciate any help of you > > Thank you > NM What did you expect? Something like this perhaps? [x,y] = meshgrid(linspace(-1, 1, 50), linspace(-1, 1, 50)); z = (x.^2 + 2*y.^2); surf(x,y,z)
From: Steven Lord on 17 Dec 2009 13:16 "Nikolas tuc" <nmihailidis(a)gmail.com> wrote in message news:hgdrmv$5ov$1(a)fred.mathworks.com... > Hi there, > > I would like to ask you how can I plot a the following surface: > > x = linspace(-1, 1, 50); > y = linspace(-1, 1, 50); > z = (x.^2 + 2*y.^2); > > figure(1), surf([x' y' z']) > > The results that i get are not the expected ones. It may not be the result you expected, but it is the correct result for the way you called it. When you call SURF with one input, you're using the SURF(Z) syntax as described in the help: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/surf.html So what you see is the surface whose values along the line segment x = 1, y = 1:50 are linspace(-1, 1, 50), whose values along the line segment x = 2, y = 1:50 are also linspace(-1, 1, 50) and whose values along the line segment x = 3, y = 1:50 are basically 3*linspace(-1, 1, 50).^2. If what you want to do is create a surface plot of the function z = x.^2+2*y.^2 over the square bounded by the lines x = -1, x = 1, y = -1, and y = 1 then you need to generate a grid of points at which you evaluate the values of the function, evaluate the function on those grid points, then call SURF with _three_ input arguments, not one. t = linspace(-1, 1, 50); [x, y] = meshgrid(t, t); z = x.^2 + 2*y.^2; surf(x, y, z) -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: plsregress constraint Next: Problems |