648
Le logiciel R
# Placez vous dans le dossier contenant votre package:
cd C:\Documents and Settings\dupont\Bureau
R CMD check PetitPkgR
R CMD INSTALL --build PetitPkgR
7.9- Installez votre package PetitPkgR.zip. Pour cela, tapez par exemple :
help(package="PetitPkgR")
help(d)
Solutions des TPs du chapitre 8
Calcul matriciel, optimisation, int´ egration
A- Un premier probl` eme d’optimisation
8.1- A <- matrix(c(2,3,5,4),nrow=2,ncol=2)
myf <- function(x) {
res <- det(A-x * diag(2))
return(res)
}
8.2- myf <- function(x) {
n <- length(x)
res <- rep(NA,n)
for (i in 1:n) res[i] <- det(A-x[i] * diag(2))
return(res)
}
8.3- curve(myf,xlim=c(-10,10))
abline(h=0,v=0)
Notez que l’on peut utiliser l’instruction locator(2)$x pour « trouver »
les deux racines.
8.4- uniroot(myf,lower=-5,upper=0)$root
uniroot(myf,lower=0,upper=10)$root
8.5- Le polynome s’´ ecrit P(x) = −7 − 6x + x
2 . Ses racines sont obtenues ainsi :
polyroot(c(-7,-6,1))
8.6- eigen(A)$values
Le logiciel R
# Placez vous dans le dossier contenant votre package:
cd C:\Documents and Settings\dupont\Bureau
R CMD check PetitPkgR
R CMD INSTALL --build PetitPkgR
7.9- Installez votre package PetitPkgR.zip. Pour cela, tapez par exemple :
help(package="PetitPkgR")
help(d)
Solutions des TPs du chapitre 8
Calcul matriciel, optimisation, int´ egration
A- Un premier probl` eme d’optimisation
8.1- A <- matrix(c(2,3,5,4),nrow=2,ncol=2)
myf <- function(x) {
res <- det(A-x * diag(2))
return(res)
}
8.2- myf <- function(x) {
n <- length(x)
res <- rep(NA,n)
for (i in 1:n) res[i] <- det(A-x[i] * diag(2))
return(res)
}
8.3- curve(myf,xlim=c(-10,10))
abline(h=0,v=0)
Notez que l’on peut utiliser l’instruction locator(2)$x pour « trouver »
les deux racines.
8.4- uniroot(myf,lower=-5,upper=0)$root
uniroot(myf,lower=0,upper=10)$root
8.5- Le polynome s’´ ecrit P(x) = −7 − 6x + x
2 . Ses racines sont obtenues ainsi :
polyroot(c(-7,-6,1))
8.6- eigen(A)$values
