Graphes

EXO 1

Dessiner la fonction sinus (en vert) et la fonction cosinus (en rouge) dans la même fenêtre graphique. Pour cela : on créera un chemin \(t\) allant de \(t_0 = −5\) à \(t_1 = 5\) et on calculera \(y_1 = sin(t)\) et \(y_2 = cos(t)\). Donner un titre.


t0 = -5 ; t1 = 5

plot(sin, from = t0, to = t1, col = "red", ylab = "", main = "Sin(x) et Cos(x)")

f = function(x) {cos(x)}
curve(f, add = TRUE, col = "green")

y1 = sin(t1)
y2 = cos(t1)

EXO 2

Dessiner côte à côte, dans 4 graphiques différents, les densités gaussiennes \(\mathcal N(0,1)\), \(\mathcal N(2,0.5)\), \(\mathcal N(−2,1.5)\), \(\mathcal N(0,3)\). On veut les mêmes échelles en abscisse et ordonnées. Utiliser xlim=c(.,.) et ylim=c(.,.).

Sur le même graphique

f1 = function(x) {dnorm(x, mean = 0, sd = sqrt(1))}
f2 = function(x) {dnorm(x, mean = 2, sd = sqrt(0.5))}
f3 = function(x) {dnorm(x, mean = -2, sd = sqrt(1.5))}
f4 = function(x) {dnorm(x, mean = 0, sd = sqrt(3))}

curve(f1, col = "green", xlim = c(-10,10), ylim = c(0,0.6) , ylab = "", main = "N(0,1), N(2,0.5), N(−2,1.5), N(0,3)")
curve(f2, add = TRUE, col = "red")
curve(f3, add = TRUE, col = "blue")
curve(f4, add = TRUE, col = "yellow")

Sur des graphiques fifférents

par(mfrow = c(1,4))   # 1 ligne, 4 colonnes
curve(f1, col = "green", xlim = c(-10,10), ylim = c(0,0.6) , ylab = "", main = "N(0,1)")
curve(f2, col = "red", xlim = c(-10,10), ylim = c(0,0.6) , ylab = "", main = "N(2,0.5)")
curve(f3, col = "blue", xlim = c(-10,10), ylim = c(0,0.6) , ylab = "", main = "N(−2,1.5)")
curve(f4, col = "yellow", xlim = c(-10,10), ylim = c(0,0.6) , ylab = "", main = "N(0,3)")

EXO 3

Faire les 4 mêmes courbes dans 2 graphes côte à côte et 2 dessous.

par(mfrow = c(2,2))

curve(f1, col = "green", xlim = c(-10,10), ylim = c(0,0.6) , ylab = '', main = "N(0,1)")
curve(f2, col = "red", xlim = c(-10,10), ylim = c(0,0.6) , ylab = '', main = "N(2,0.5)")
curve(f3, col = "blue", xlim = c(-10,10), ylim = c(0,0.6) , ylab = '', main = "N(−2,1.5)")
curve(f4, col = "yellow", xlim = c(-10,10), ylim = c(0,0.6) , ylab = '', main = "N(0,3)")