Three pieces graph function $f(x)$

154 Views Asked by At

I need to build a function to draw this shape on a graph plot.

enter image description here

Basically, it has three parts:

\begin{align*}\require{color}&\color{blue}{y=-\sqrt{1-(1+x)^2}}\\ &\color{red}{y=\sqrt{1-(1-x)^2}}\\ &\color{green}{y=\sqrt{4-x^2}}\end{align*}

Is it possible to merge these three formulas into one and how it would look like?

Cheers!

1

There are 1 best solutions below

2
On

Strictly speaking a single function with that plot cannot be achieved. This is because a function is an object that takes an input and produces a single output. The plot of a function represents how the output of a function behaves. If the point $(x,y)$ is in the plot that means $f(x)=y$.

If two different points on our plot were to to share the same $x$ coordinate but have different $y$ coordinates we would have a problem. Let's say we have the coordinates $(x,y_0)$ and $(x,y_1)$, this means

$$ f(x) = y_0 \\ f(x) = y_1 \\ y_0 \neq y_1 \\ $$

Therfor

$$ f(x) \neq f(x) $$

This problem arises because our plot is saying that $f(x)$ equals two different things.

Since $f(x)$ can only be one thing no two points in the same vertical line (sharing an $x$ coordinate) can be a part of our plot. This give rise to the vertical line test I mentioned in my comment. If any vertical line passes through the plot more than once it cannot represent a function.

The plot that you have fails the vertical line test and thus cannot be a function.

However as you point out in the comments we could have two functions that when plotted together draw your plot, like the batman curve you linked. For your particular curve this is not that hard. The first function is just the green function you already included.

$$ f(x) = \sqrt{4-x^2} $$

The other two functions need to be combined. This can be done piece-wise

$$ g(x) = \begin{cases}-\sqrt{1-(1+x)^2} & x<0 \\ \sqrt{1-(1-x)^2)} & x\ge0\end{cases} $$

If we really want to we can rewrite this as a single function:

$$ g(x)= -\dfrac{|x|}{x}\sqrt{1-(1-|x|)^2} $$

However while on paper this might not look piece-wise because absolute value is a piece-wise function,

$$ |x| = \begin{cases} -x & x<0 \\ x & x\geq 0\\ \end{cases} $$

Our end result is really just a workaround.

Once we have both of these functions in a form we like we can plot them both in the same way that a batman curve was done.


Another option for plotting is a relation. Unlike a function a relation takes two pieces of input and is either true or false based on a rule. When we plot a relation a point $(x,y)$ is drawn on our plot iff it satisfies our relation (the relation is true when given $x$ and $y$). For example to plot a circle one can plot the following relation:

$$ P(x,y) := 1=x^2+y^2 $$

Here we use two different "equals" symbols $=$ and $:=$. $=$ can be thought of as asking a question it is either true or false. Whereas the $:=$ symbol (usually called defined as) forces something to be true. In this way that statement in English means

When we ask $P(x,y)$ that is the same as asking whether 1 is equal to $x^2+y^2$.

We might notice that plotting a function is really the same as plotting a relation that is true if $y=f(x)$. This is something I think a lot of times is glossed over when it comes to plotting, but is pretty crucial to what plotting actually is.

Relations are much more lax than functions, as we see in the circle example they don't have to pass the vertical line test. In fact anything you can define with a rule, can be represented as the plot of a relation. So we can define your curve as a single relation. In fact we can use the two functions from earlier to do this quite easily.

$$ P(x,y) := (y=f(x)) \lor (y=g(x)) $$

Here $\lor$ is a logical operator called "or". It is very similar to the sense of the English word "or" in that $A\lor B$ is only false if both $A$ and $B$ are false.

Together this statement reads,

Plot the point $(x,y)$ if you would have plotted it when drawing $y=f(x)$ or if you would have plotted it when drawing $y=g(x)$.

By joining the two relations with an or we get a single relation that plots both of them.

I hope this was the answer you were looking for. (For what it's worth I used to be obsessed with trying to draw things with functions and relations. I've tried to make this answer the answer I would have wanted when I was in High school)