How to plot this function?

217 Views Asked by At

I would like to plot this function:

$\sqrt[\gamma]{(\frac{x}{a})^{\gamma}+(\frac{y}{b})^{\gamma}}=\mu \,$ where $\, \gamma, a,b\in \mathbb{R} \,$ and $\, \mu \in \mathbb{Z}$

I have tried to plot this function in MATLAB considering $\gamma=0.43$, $ a=0.2$, $b=0.55$, $\mu=2$, but it looks so ugly. I am wonder if my method is correct. Here is what I do:
First) Rearrange the equation .
Second) Plot it with a simple code:

$y=\pm b\times\sqrt[{\gamma}]{{\mu^{\gamma}-(\frac{x}{a})^{\gamma}}}$

Here is a code I use in MATLAB to plot this function:

g=0.2; a =0.4; b=0.6; m=1;

x= - a*m :0.01: a*m;

y=  +b*(m^g-(x/a).^g).^(1/g);
yy= -b*(m^g-(x/a).^g).^(1/g);

plot(x,y,x,yy)

The result should be a nice closed shape called superellipse. But it is not.

Is what I've done mathematically correct?

enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

Firstly your function needs absolute values in it if you want to evaluate the fractional powers correctly.

$$\sqrt[\gamma]{(\frac{|x|}{a})^{\gamma}+(\frac{|y|}{b})^{\gamma}}=\mu \,$$

Also your function does not need the $\mu$ term as it can be rearranged as:

$$\sqrt[\gamma]{(\frac{|x|}{a\cdot\mu})^{\gamma}+(\frac{|y|}{b\cdot\mu})^{\gamma}}=1$$

Regardless your function can then be written as:

$$y=\pm b\cdot\mu\times\sqrt[{\gamma}]{{1-(\frac{|x|}{a\cdot\mu})^{\gamma}}}$$

This shows that your range of $x$ should be $[-a\cdot\mu,a\cdot\mu]$ whereas in your example you have used a much bigger range for $x$. This may be the cause of your problem.

Lastly most computer programs will have difficulty near $x=0$ as the slope of the curve there is approaching infinity and any small increment in the $x$ direction can result in a large change in the $y$ which may be calculated poorly. This is probably also contributing to your problem.

Without a picture to tell exactly what you graph looks like there isn't much more I can say.

0
On

To answer your specific question, what have I done wrong?, the answer is that you need the abs(x/a) in the expressions for y and yy.

For a more thoughtful discussion of the superellipse and related curves see my posting here: Polar form of generalized superellipse.