I've written a multiline function using LaTex, but then I can't seem to work out how to plot it.

I don't know where to go from here!

Any help is greatly appreciated.

Thank you

I've written a multiline function using LaTex, but then I can't seem to work out how to plot it.

f(x) =
\begin{cases}
\frac{12}{7}(1+x)^2 & \quad \text{for} \; -1< x \leq 0\\
\frac{12}{7}(1-x)^3 & \quad \text{for} \; 0< x < 1\\
0 & \quad \text{otherwise}
\end{cases}

I don't know where to go from here!

Any help is greatly appreciated.

Thank you

Thank you so much for the response. I'm just trying to plot the function for the different values of x as you've mentioned. I just don't know how to do it for multiline functions like the one in this case. Especially with the differing domains.

Your help is greatly appreciated.

Are you new to programming? In this situations, the `if - else if - else`

is almost always the most obvious solution. Add the first case under `if`

, and in case there are more, add those conditions one by one under `else if`

. If all the cases are collectively exhaustive, you can use `else`

in the final one, as there's only one possibility left.

See below:

```
f <- function(x)
{
if ((-1 < x) & (x <= 0))
{
return((12 / 7) * ((1 + x) ^ 2))
} else if ((0 < x) & (x < 1))
{
return((12 / 7) * ((1 + x) ^ 3))
} else
{
return(0)
}
}
x_vals <- seq(from = -2,
to = 2,
by = 0.01)
y_vals <- sapply(X = x_vals,
FUN = f)
plot(x = x_vals,
y = y_vals)
```

^{Created on 2019-04-01 by the reprex package (v0.2.1)}

I didn't join the points, you can do that by specifying `type="l"`

. Hope this helps.

**PS** I'm changing the category of your post, as it doesn't relate to either R Markdown or latex. Hope you don't mind.

**PPS** You can write LaTeX equations within a pair of $$ in R markdown. Check my edit in the question.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.