Write R code to plot the graph of the following in one plot graph of the function f(x)=x^2+1 in range (-2,2)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Heya,
Hereβs the R code to plot the function f(x)=x2+1f(x) = x^2 + 1f(x)=x2+1 over the range [β2,2][-2, 2][β2,2]:
Hi,
Sure thing! Hereβs a quick and simple way to plot the graph of the function ( f(x) = x^2 + 1 ) in the range ([-2, 2]) using R:
Explanation:
f(x) = x^2 + 1
.x
ranging from-2
to2
with small increments (by = 0.01
) for smooth plotting.plot()
function is used to create the plot, wheretype = 'l'
specifies a line plot.col = 'blue'
to give the line a nice color, andlwd = 2
to make it a bit thicker for better visibility.grid()
to add a grid to the plot, which makes it easier to interpret the graph.Happy coding! π¨π
- Bobby