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: enter image description here

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:

sodp

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:

sphere

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

Popular posts from this blog

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -