matlab - How to plot a sphere function? -
i tried plotting sphere to this.
this earlier question contains code tried plotting.
that previous question answered, having trouble plotting sphere function shown in plot given link above.
edit sphere function using:
function ph = spherefn(x) ph = sum(x.*x, 2); end
edit outcome should this:
nb: have changed function sphere spherefn avoid conflict matlab sphere.
your spherefn
may not doing expect do. looks trying implement sum of different powers
test based on function:
however, implementation as:
ph = sum(x.*x, 2);
does not resemble function. how using starting point:
x = linspace(-1,1,25); i=1:size(x,2) j=1:size(x,2) s(i,j) = abs(x(i))^2 + abs(x(j))^3; end end [xx,yy] = meshgrid(linspace(-1,1,25)); surfc(xx,yy,s)
as in essence describing 2d problem, crude implementation of function suffice. can put nested for
-loops function called sum_of_different_powers_2d
(for example) , call it, passing vector x
.
edit
you may shape looks more intended surface replace command inside nested for
-loops with:
s(i,j) = abs(x(i))^2 + abs(x(j))^2;
this resemble function:
edit 2
it important understand n
in equation quoted above dimension of problem. which, showed, 2
.
edit 3
i recommend use function:
function ph = spherefn(x) i=1:size(x,2) j=1:size(x,2) ph(i,j) = abs(x(i))^2 + abs(x(j))^2; end end end
Comments
Post a Comment