Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
? plotting a p-ball

Subject: ? plotting a p-ball

From: Cheng Cosine

Date: 10 Apr, 2010 23:09:21

Message: 1 of 6

Hi:

 Are there existing mfile or do anyone know how can one plot the
region of a p-ball?

P-ball comes from the definition of p-norm below.

 norm(x, p) = ( sum( abs(x(i))^p, i = 1 to N ) )^(1/p)

e.g., norm(x, 1) = sum( abs(x(i)), i = 1 to N )

        norm(x, inf) = max( abs(x(i)), i = 1 to N )

 So p-ball is a rotated square having vertices on coordinate axes when
p = 1.

 P-ball is a 2d circle or 3d sphere when p = 2.

How to use Matlab to plot these p-balls for a given p value?

 Thanks,

Subject: ? plotting a p-ball

From: Roger Stafford

Date: 11 Apr, 2010 00:13:05

Message: 2 of 6

Cheng Cosine <asecant@gmail.com> wrote in message <2b945620-b6ef-4955-a20f-e37e2c7ee92c@k33g2000yqc.googlegroups.com>...
> Hi:
>
> Are there existing mfile or do anyone know how can one plot the
> region of a p-ball?
>
> P-ball comes from the definition of p-norm below.
>
> norm(x, p) = ( sum( abs(x(i))^p, i = 1 to N ) )^(1/p)
>
> e.g., norm(x, 1) = sum( abs(x(i)), i = 1 to N )
>
> norm(x, inf) = max( abs(x(i)), i = 1 to N )
>
> So p-ball is a rotated square having vertices on coordinate axes when
> p = 1.
>
> P-ball is a 2d circle or 3d sphere when p = 2.
>
> How to use Matlab to plot these p-balls for a given p value?
>
> Thanks,

  In two dimensions a "p-ball" plotting centered at the origin can easily be done parametrically:

 t = linspace(pi,3*pi);
 x = r*sign(cos(x)).*abs(cos(t)).^(2/p);
 y = r*sign(sin(x)).*abs(sin(t)).^(2/p);
 plot(x,y,'y-')
 axis square

In three dimensions some analogous adaptation of spherical coordinates ought to be sufficient for the job. For higher dimensions, the problem becomes one of realizing such plots in a manner that us mere human beings can interpret.

Roger Stafford

Subject: ? plotting a p-ball

From: Cheng Cosine

Date: 11 Apr, 2010 02:21:11

Message: 3 of 6

On Apr 10, 8:13 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> Cheng Cosine <asec...@gmail.com> wrote in message <2b945620-b6ef-4955-a20f-e37e2c7ee...@k33g2000yqc.googlegroups.com>...
> > Hi:
>
> >  Are there existing mfile or do anyone know how can one plot the
> > region of a p-ball?
>
> > P-ball comes from the definition of p-norm below.
>
> >  norm(x, p) = ( sum( abs(x(i))^p, i = 1 to N ) )^(1/p)
>
> > e.g., norm(x, 1) = sum( abs(x(i)), i = 1 to N )
>
> >         norm(x, inf) = max( abs(x(i)), i = 1 to N )
>
> >  So p-ball is a rotated square having vertices on coordinate axes when
> > p = 1.
>
> >  P-ball is a 2d circle or 3d sphere when p = 2.
>
> > How to use Matlab to plot these p-balls for a given p value?
>
> >  Thanks,
>
>   In two dimensions a "p-ball" plotting centered at the origin can easily be done parametrically:
>
>  t = linspace(pi,3*pi);
>  x = r*sign(cos(x)).*abs(cos(t)).^(2/p);
>  y = r*sign(sin(x)).*abs(sin(t)).^(2/p);
>  plot(x,y,'y-')
>  axis square
>
> In three dimensions some analogous adaptation of spherical coordinates ought to be sufficient for the job.  For higher dimensions, the problem becomes one of realizing such plots in a manner that us mere human beings can interpret.
>
> Roger Stafford- Hide quoted text -
>
> - Show quoted text -

Thanks, Roger; it worked perfectly.

 But would you explain more about why abs(cos(t)).^(2/p), instead of
abs(cos(t)).^(1/p)?

Thank you,

Subject: ? plotting a p-ball

From: Roger Stafford

Date: 11 Apr, 2010 05:19:03

Message: 4 of 6

Cheng Cosine <asecant@gmail.com> wrote in message <20807c9e-255f-415e-8ac2-35cfcfef0702@12g2000yqi.googlegroups.com>...
> On Apr 10, 8:13 pm, "Roger Stafford"
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> > .....
> >  x = r*sign(cos(x)).*abs(cos(t)).^(2/p); [<--Wrong!]
> >  y = r*sign(sin(x)).*abs(sin(t)).^(2/p);
> > .....
>
> But would you explain more about why abs(cos(t)).^(2/p), instead of
> abs(cos(t)).^(1/p)?
> ......
----------------
  That was necessary to make the plotted points all lie the same p-distance from the origin, namely r, (we assume r is positive):

 abs(x)^p+abs(y)^p =
 r^p*(abs(cos(t))^(2/p))^p + r^p*(abs(sin(t))^(2/p))^p =
 r^p*(cos(t)^2+sin(t)^2) = r^p*1 = r^p

Therefore the p-norm of each point (x,y) on this plot is equal to:

 (abs(x)^p+abs(y)^p)^(1/p) = (r^p)^(1/p) = r

which is a constant, making the plot a "p-ball" of p-radius r in two dimensions. (Of course the ordinary radius will not be constant at all.)

  You can easily verify that all this is true numerically, aside from round off variations.

  A question. Did you have just two dimensional plotting in mind when you asked the original question?

  I'm sorry about the errors in the original code. It should have read:

 t = linspace(0,2*pi);
 x = r*sign(cos(t)).*abs(cos(t)).^(2/p);
 y = r*sign(sin(t)).*abs(sin(t)).^(2/p);
 plot(x,y,'y-')
 axis square

Roger Stafford

Subject: ? plotting a p-ball

From: Cheng Cosine

Date: 11 Apr, 2010 12:39:27

Message: 5 of 6

Thanks Roger; it becomes clearer to me now. :)

 My original thought is to have some visualizing tool to understand
the p-ball, and 2D is the most simple one to start with. But,
according to your 1st replying, it seems that we do not have
parametric formulations for p-ball in a dimension higher than 3? Thus,
we do not even have a way to generate numerical data of p-ball in
higher spatial dimensions, and then strive to figure out a way to
visualize the data?

 In 3D we have spherical parametric expression, but I do not recall
one for 4D or higher D's.

 Thank you,

Subject: ? plotting a p-ball

From: Roger Stafford

Date: 11 Apr, 2010 23:25:05

Message: 6 of 6

Cheng Cosine <asecant@gmail.com> wrote in message <761f880b-8c7b-48e5-8f40-7f9f12647988@x3g2000yqd.googlegroups.com>...
> Thanks Roger; it becomes clearer to me now. :)
>
> My original thought is to have some visualizing tool to understand
> the p-ball, and 2D is the most simple one to start with. But,
> according to your 1st replying, it seems that we do not have
> parametric formulations for p-ball in a dimension higher than 3? Thus,
> we do not even have a way to generate numerical data of p-ball in
> higher spatial dimensions, and then strive to figure out a way to
> visualize the data?
>
> In 3D we have spherical parametric expression, but I do not recall
> one for 4D or higher D's.
>
> Thank you,
----------------
  I think it is time to make some remarks about terminology here. Mathematicians, at least the ones I am familiar with, distinguish between the terms 'circle' or 'sphere' on the one hand and 'disk' and 'ball' on the other hand. A circle in two dimensions and a sphere in three dimensions consist of all points whose distance from a central point is equal to a given constant, the radius. A disk in two dimensions or a ball in three dimensions consist of all points whose distance from a central point is less than or equal to its radius. In other words a (closed) ball would be all points on, or within the interior of, a sphere. A disk is all points on, or within the interior of, a circle. A sphere would be the surface of a ball. A circle would be the periphery of a disk.

  For this reason it would seem more appropriate with respect to a p-norm metric to call the objects you have been dealing with p-circles, p-spheres, or p-hyperspheres, and you could call the points on or within their interiors p-disks or p-balls. In that terminology the point sets I generated yesterday would have to be called p-circles rather than p-disks or p-balls.


  In answer to your question above, in four dimensions one can define a system of hyperspherical coordinates, t1, t2, t3, and r, which are related to the cartesian coordinates x1, x2, x3, and x4 by the equations

 x1 = r*sin(t3)*sin(t2)*sin(t1)
 x2 = r*sin(t3)*sin(t2)*cos(t1)
 x3 = r*sin(t3)*cos(t2)
 x4 = r*cos(t3)

where 0 <= t1 <= 2*pi, 0 <= t2 <= pi, 0 <= t3 <= pi, and 0 <= r. The inverse of these is

 t1 = atan2(x1,x2)
 t2 = atan2(sqrt(x1^2+x2^2),x3)
 t3 = atan2(sqrt(x1^2+x2^2+x3^2),x4)
 r = sqrt(x1^2+x2^2+x3^2+x4^2)

which are well defined except in the cases x1 = x2 = 0.

  Inspired by this, we can define a four dimensional p-hypersphere of fixed radius r and centered at the origin using parameters t1, t2, and t3 as follows:

 [t1,t2,t3] = ndgrid(0:pi/n:2*pi,0:pi/n:pi,0:pi/n:pi);
 x1 = r*sign(sin(t1)).*abs(sin(t3).*sin(t2).*sin(t1)).^(2/p);
 x2 = r*sign(cos(t1)).*abs(sin(t3).*sin(t2).*cos(t1)).^(2/p);
 x3 = r*sign(cos(t2)).*abs(sin(t3).*cos(t2)).^(2/p);
 x4 = r*sign(cos(t3)).*abs(cos(t3)).^(2/p);

Each of the points (x1,x2,x3,x4) thus defined belongs to the indicated p-hypersphere as can be tested by checking that

 (x1.^p+x2.^p+x3.^p+x4.^p).^(1/p) = r

(to within round off accuracy of course.) The big question is, how are you going to display this three parameter mesh in four dimensions? All we can effectively envision are 3D "slices" of this monster.

  The generalization of this example to higher dimensions is easily made, but these continue to have the same difficulty that such p-hyperspheres are very difficult for us creatures to have displayed for us with our limited three-dimensional brains.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us