Although Stackoverflow is not a place to go home, in addition to showing what you tried to plot a curve might be interesting for other future issues.
The problem seems to be in its interpretation (Google made a very consistent translation from English to Portuguese) of how to use the function curve
or plot
.
- a. Trace the cosine of x (-10 < = x < = 10) as a function of x.
Plot x
vs cos(x)
.
Code:
a<- seq(from=-10,to=10,by=0.5)
b<- cos(a)
plot(a,b)
This generates a dotted graph. In this case I used seq
, but a<- -10:10
also works, but with fewer points because the range is 1. If you use a function as data for plot
(be it your function, as you did or the library) it has the same behavior as curve
, but if you put data, it looks like you use the plot.
On your output, you only have a curve between 0 and 1, in the above code, you will see points between -10 and 10.
- b. How to make a chart with a smooth curve? (Smooth = Continuous)
He that is a solid line, not points. Just use the type='l'
tag. Code:
plot(a,b,type='l')
- c. Plot the same graph in a single statement, but using the
curve
function.
As you've already put it, it wants to use the curve
to generate the graph. It reproduces any equation (of x) you place as an argument. In your example, you are using the dnorm
function that generates a distribution normal. Simply replace dnorm
with cos
and delimit values between -10 and 10, using from
and to
.
curve(cos(x),from=-10,to=10)