Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Computational tools for E&F, Esercizi di Economia

Appunti di computational tools for economics and management

Tipologia: Esercizi

2020/2021

Caricato il 17/02/2021

Alessandra9393
Alessandra9393 🇮🇹

4.8

(5)

8 documenti

1 / 56

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
> # Answer: -3.25
>
> ############################################################
>
> # EX. (2) 132
>
> y1<- function(x) -2*x+3
> y2<- function(x) x^2+x+1
> plot(y1,-2,2)
> ## We are not able to see well the exact ordinate
> optimize(y1,c(-2,2))
$minimum
[1] 1.99994
$objective
[1] -0.9998794
> ## The lowest ordinate is -1
> plot(y2,-2,2)
> ## The lowest ordinate is 3
>
> # Answer: -1
>
> ############################################################
>
> # EX. (2) 133
>
> y1<- function(x) x+1
> y2<- function(x) x^2+2*x+4
> plot(y1,-2,3)
> ## The lowest ordinate is -1
> plot(y2,-2,3)
> optimize(y2,c(-2,3))
$minimum
[1] -1
$objective
[1] 3
> ## The lowest ordinate is 3
>
> # Answer: -1
>
> ############################################################
>
> # EX. (2) 134
>
> y1<- function(x) 2*x-2
> y2<- function(x) x^2+2*x-5
> plot(y1,-1,2)
> ## The lowest ordinate is -4
> plot(y2,-1,2)
> ## The lowest ordinate is -6
>
> # Answer: -6
>
> ############################################################
>
> # EX. (2) 135
>
> y1<- function(x) x-1
> y2<- function(x) -x^2-2*x-1
> plot(y1,-2,1)
> ## The lowest ordinate is -3
> plot(y2,-2,1)
> ## The lowest ordinate is -4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38

Anteprima parziale del testo

Scarica Computational tools for E&F e più Esercizi in PDF di Economia solo su Docsity!

> # Answer: -3. > > ############################################################ > > # EX. (2) 132 > > y1<- function(x) -2*x+ 3 > y2<- function(x) x^ 2 +x+ 1 > plot(y1,-2, 2 ) > ## We are not able to see well the exact ordinate > optimize(y1,c(-2, 2 )) $minimum [ 1 ] 1. $objective [ 1 ] -0. > ## The lowest ordinate is - > plot(y2,-2, 2 ) > ## The lowest ordinate is 3 > > # Answer: - > > ############################################################ > > # EX. (2) 133 > > y1<- function(x) x+ 1 > y2<- function(x) x^ 2 + 2 *x+ 4 > plot(y1,-2, 3 ) > ## The lowest ordinate is - > plot(y2,-2, 3 ) > optimize(y2,c(-2, 3 )) $minimum [ 1 ] - $objective [ 1 ] 3 > ## The lowest ordinate is 3 > > # Answer: - > > ############################################################ > > # EX. (2) 134 > > y1<- function(x) 2 *x- 2 > y2<- function(x) x^ 2 + 2 *x- 5 > plot(y1,-1, 2 ) > ## The lowest ordinate is - > plot(y2,-1, 2 ) > ## The lowest ordinate is - > > # Answer: - > > ############################################################ > > # EX. (2) 135 > > y1<- function(x) x- 1 > y2<- function(x) - x^ 2 - 2 *x- 1 > plot(y1,-2, 1 ) > ## The lowest ordinate is - > plot(y2,-2, 1 ) > ## The lowest ordinate is -

> ## The lowest ordinate is - > > # Answer: - > > ############################################################ > > # EX. (2) 136 > > y1<- function(x) 2 x- 2 > y2<- function(x) x^ 2 + 2 x- 5 > plot(y1,-1, 4 ) > ## The lowest ordinate is - > plot(y2,-1, 4 ) > optimize(y2,c(-1, 4 )) $minimum [ 1 ] -0. $objective [ 1 ] - > ## The lowest ordinate is - > > # Answer: - > > ############################################################ > > # EX. (2) 137 > > y1<- function(x) -x+ > y2<- function(x) x^2-2x- > plot(y1,-2,2) > ## The lowest ordinate is - > plot(y2,-2,2) > ## The lowest ordinate is - > > # Answer: - > > ############################################################ > > # EX. (2) 138 > > y1<- function(x) -x+ > y2<- function(x) x^2-2x+ > plot(y1,-1,3) > ## The lowest ordinate is - > plot(y2,-1,3) > ## The lowest ordinate is 1 > > # Answer: - > > ############################################################ > > # EX. (2) 139 > > y1<- function(x) -2*x+ > y2<- function(x) -x^2-x+ > plot(y1,-2,1) > ## The lowest ordinate is - > plot(y2,-2,1) > ## The lowest ordinate is - > > # Answer: - > > ############################################################ > > # EX. (2) 140

> ## The lowest ordinate is - > plot(y2,-2,1) > ## The lowest ordinate is 2 > > # Answer: - > > ############################################################ > > # EX. (3) 101 > > 2(-1:2) [1] 0.5 1.0 2.0 4. > 1: [1] 1 2 3 4 5 6 > > # Answer: (b) The last recycled number was 1 > > ############################################################ > > # EX. (3) 102 > > 2(1:3) [1] 2 4 8 > 1: [1] 1 2 3 4 5 6 > > # Answer: (c) The last recycled number was 8 > > ############################################################ > > # EX. (3) 103 > > exp(0:2) [1] 1.000000 2.718282 7. > 1: [1] 1 2 3 > > # Answer: (c) There was no need to recycle any argument > > ############################################################ > > # EX. (3) 131 > > abs(0:3) [1] 0 1 2 3 > log(1:5) [1] 0.0000000 0.6931472 1.0986123 1.3862944 1. > > # Answer: (c) The first recycled number was 0 > > ############################################################ > > # EX. (3) 132 > > exp(-1:2) [1] 0.3678794 1.0000000 2.7182818 7. > log(1:3) [1] 0.0000000 0.6931472 1. > > # Answer: (d) The last recycled number was 0 > > ############################################################ > > # EX. (3) 133 > > exp(1:2)

[1] 2.718282 7.

> log(1:6) [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1. > > # Answer: (c) The last recycled number was 7. > > ############################################################ > > # EX. (3) 134 > > 2(0:3) [1] 1 2 4 8 > 1: [1] 1 2 3 4 > > # Answer: (c) There was no need to recycle any argument > > ############################################################ > > # EX. (3) 135 > > 2(-1:2) [1] 0.5 1.0 2.0 4. > log(1:5) [1] 0.0000000 0.6931472 1.0986123 1.3862944 1. > > # Answer: (d) The last recycled number was 0. > > ############################################################ > > # EX. (3) 136 > > 2**(-1:2) [1] 0.5 1.0 2.0 4. > log(1:4) [1] 0.0000000 0.6931472 1.0986123 1. > > # Answer: (c) There was no need to recycle any argument > > ############################################################ > > # EX. (3) 137 > > exp(-1:3) [1] 0.3678794 1.0000000 2.7182818 7.3890561 20. > 1: [1] 1 2 3 4 5 > > # Answer: (a) There was no need to recycle any argument > > ############################################################ > > # EX. (3) 138 > > abs(1:2) [1] 1 2 > 1: [1] 1 2 > > # Answer: (a) There was no need to recycle any argument > > ############################################################ > > # EX. (3) 139 > > exp(1:3)

> # Answer: (c) > > ############################################################ > > # EX. (4) 135 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(x) > h<- function(x) 2.8x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (c) > > ############################################################ > > # EX. (4) 136 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(0.9x) > h<- function(x) -13x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (a) > > ############################################################ > > # EX. (4) 137 > > # Answer: (d) Simulation can answer the question 'What's the average outcome of my experiment?' > > ############################################################ > > # EX. (4) 138 > > # Answer: (a) Simulation can be used to estimate how probable is an event > > ############################################################ > > # EX. (4) 139 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(x) > h<- function(x) -6x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (d) > > ############################################################ > > # EX. (4) 140 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(x) > h<- function(x) -12*x+

> h<- function(x) -12x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (c) > > ############################################################ > > # EX. (4) 101 > > # Answer: (a) A distribution is a description of a random experiment > > ############################################################ > > # EX. (4) 102 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(x) > h<- function(x) -2x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (d) > > ############################################################ > > # EX. (4) 103 > > x<- seq(0.4,3,len=11) > y<- 10+sin(10x) > g<- function(x) exp(x) > h<- function(x) -6x+ > plot(g,0,3) > plot(h,0,3,add=T) > points(x,y,pch=20) > > # Answer: (c) > > ############################################################ > > # EX. (5) 101 > > set.seed(108) > v<- rnorm(100,-2,3) > sum(v[11:21]) [1] -25. > > # Answer: -25. > > ############################################################ > > # EX. (5) 102 > > set.seed(180) > A<- matrix(runif(9),3,3) > A [,1] [,2] [,3] [1,] 0.2905956 0.32568568 0. [2,] 0.8499301 0.88765772 0. [3,] 0.6784619 0.09354346 0. > b<- c(0,2,1) > A%%b [,1]

> set.seed(171) > A<- matrix(runif(9),3,3) > b<- c(2,0,1) > u<- A%%b > sum(u) [1] 3. > > # Answer: 3. > > ############################################################ > > # EX. (5) 135 > > set.seed(182) > A<- matrix(runif(12),4,3) > b<- c(1,-2,-1) > u<- A%%b > sum(u) [1] -4. > > # Answer: -4. > > ############################################################ > > # EX. (5) 136 > > set.seed(156) > v<- rnorm(100,0,3) > sum(v[41:51]) [1] 12. > > # Answer:12. > > ############################################################ > > # EX. (5) 137 > > set.seed(157) > A<- matrix(runif(6),2,3) > b<- c(2,-2,1) > u<- A%%b > sum(u) [1] 0. > > # Answer: 0.11 (?) > > ############################################################ > > # EX. (5) 138 > > set.seed(178) > v<- rnorm(100,-3,1) > sum(v[31:43]) [1] -38. > > # Answer: -38. > > ############################################################ > > # EX. (5) 139 > > set.seed(166) > A<- matrix(runif(6),2,3) > b<- c(2,-2,-1) > u<- A%%b > sum(u)

[1] -1.

> # Answer: -1. > > ############################################################ > > # EX. (5) 140 > > set.seed(149) > A<- matrix(runif(12),4,3) > b<- c(-2,1,0) > u<- A%%b > sum(u) [1] -2. > > # Answer: -2. > > ############################################################ > > # EX. (6) 131 > > f<- function(x) x^4-x^3+2x^2-2x- > optimize(f,c(-3,0),maximum=T) $maximum [1] -2. $objective [1] 128. > > # Answer: 129 > > ############################################################ > > # EX. (6) 132 > > f<- function(x) -x^4+3x^3+3x^2-x- > optimize(f,c(-3,1)) $minimum [1] -2. $objective [1] -133. > # Answer: - > > ############################################################ > > # EX. (6) 133 > > f<- function(x) x^4+2x^3-4x^2+3x- > optimize(f,c(-1,1),maximum=T) $maximum [1] 0. $objective [1] -0. > > # Answer: 0 > > ############################################################ > > # EX. (6) 134 >

> f<- function(x) -x^4-x^3-4x^2+2x- > plot(f,-10,10) > > # Answer: - > > ############################################################ > > # EX. (6) 140 > > f<- function(x) -x^4+x^3-x^2+x+ > plot(f,-10,10) > > # Answer: - > > ############################################################ > > # EX. (6) 101 > > f<- function(x) x^4-3x^3+3x^2-x- > plot(f,-10,10) > optimize(f,c(-5,5)) $minimum [1] 0. $objective [1] -1. > > # Answer: -1. > > ############################################################ > > # EX. (6) 102 > > f<- function(x) -x^4+4x^3-x^2-3x+ > optimize(f,c(-1,1)) $minimum [1] 0. $objective [1] 2. > > # Answer: 2.54 (?) > > ############################################################ > > # EX. (6) 103 > > f<- function(x) x^4-2x^3+2x^2+x- > optimize(f,c(-1,3)) $minimum [1] -0. $objective [1] -3. > > # Answer: -3. > > ############################################################ > > # EX. (7) 101 >

>> f<- function(x) 0.22exp(0.077x) > g<- function(x) 0.33+0.03x > h<- function(x) f(x)-g(x) > plot(h,0,20) > abline(h=0,col=2) > uniroot(h,c(15,20)) $root [1] 17. $f.root [1] -4.517019e- $iter [1] 5 $init.it [1] NA $estim.prec [1] 6.103516e- > > # Answer: 17. > > ############################################################ > > # EX. (7) 102 > > f<- function(x) -x^3+x^2+2x- > plot(f,-5,5) > abline(h=0,col=2) > plot(f,-2,0) > abline(h=0,col=2) > uniroot(f,c(-1.5,-1)) $root [1] -1. $f.root [1] 4.094805e- $iter [1] 4 $init.it [1] NA $estim.prec [1] 6.103516e- > > # Answer: -1. > > ############################################################ > > # EX. (7) 103 > > f<- function(x) 0.21exp(0.088x) > g<- function(x) 0.3+0.024*x > h<- function(x) f(x)-g(x) > plot(h,0,20) > abline(h=0,col=2) > uniroot(h,c(10,15)) $root [1] 11.

[ 1 ] NA

$estim.prec [ 1 ] 6.103516e- > > # Answer: -2. > > ############################################################ > > # EX. (7) 133 > > f<- function(x) x/ 100 +0.25exp(0.087x) > g<- function(x) f(x)- > plot(g, 0 , 20 ) > abline(h= 0 ,col= 2 ) > uniroot(g,c( 10 , 15 )) $root [ 1 ] 14. $f.root [ 1 ] 7.290371e- $iter [ 1 ] 4 $init.it [ 1 ] NA $estim.prec [ 1 ] 6.103516e- > > # Answer: 14. > > ############################################################ > > # EX. (7) 134 > > f<- function(x) - x^ 3 - 4 x^ 2 - 2 x+ 1 > plot(f,-5, 5 ) > abline(h= 0 ,col= 2 ) > uniroot(f,c( 0 , 2 )) $root [ 1 ] 0. $f.root [ 1 ] 7.449028e- $iter [ 1 ] 9 $init.it [ 1 ] NA $estim.prec [ 1 ] 6.103516e- > > # Answer: 0. > > ############################################################ > > # EX. (7) 135 > > f<- function(x) x/ 100 +0.2exp(0.086x)

> f<- function(x) x/ 100 +0.2exp(0.086x) > g<- function(x) f(x)- > plot(g, 0 , 20 ) > abline(h= 0 ,col= 2 ) > uniroot(g,c( 15 , 20 )) $root [ 1 ] 16. $f.root [ 1 ] -1.180642e- $iter [ 1 ] 4 $init.it [ 1 ] NA $estim.prec [ 1 ] 6.103516e- > > # Answer: 16. > > ############################################################ > > # EX. (7) 136 > > f<- function(x) - x^ 3 + 3 x^ 2 +x- 1 > plot(f,-5, 5 ) > abline(h= 0 ,col= 2 ) > plot(f,-2, 2 ) > abline(h= 0 ,col= 2 ) > uniroot(f,c(-1, 0 )) $root [ 1 ] -0. $f.root [ 1 ] -0. $iter [ 1 ] 5 $init.it [ 1 ] NA $estim.prec [ 1 ] 6.103516e- > > # Answer: -0. > > ############################################################ > > # EX. (7) 137 > > f<- function(x) x/ 100 +0.19exp(0.087*x) > g<- function(x) f(x)- > plot(g,-50, 50 ) > abline(h= 0 ,col= 2 ) > uniroot(g,c( 0 , 20 )) $root [ 1 ] 16. $f.root [ 1 ] -2.182935e-

> # Answer: 17. > > ############################################################ > > # EX. (7) 140 > > f<- function(x) x^ 3 + 3 *x^ 2 + 4 *x+ 1 > plot(f,-5, 5 ) > abline(h= 0 ,col= 2 ) > plot(f,-2, 0 ) > abline(h= 0 ,col= 2 ) > uniroot(f,c(-0.5, 0 )) $root [ 1 ] -0. $f.root [ 1 ] -5.435077e- $iter [ 1 ] 5 $init.it [ 1 ] NA $estim.prec [ 1 ] 6.103516e- > > # Answer: -0. > > ############################################################ > > # EX. (8) 131 > > f<- function(x,y) 5 *x^ 2 + 2 xy+ 4 *y^ 2 + 4 *x- 2 y- 2 > fb<- function(x) f(x[ 1 ],x[ 2 ]) > x<- seq(-5, 5 ,len= 100 ) > y<- seq(-5, 5 ,len= 100 ) > fz<- outer(x,y,f) > persp(x,y,fz) > > # Answer: - > > ############################################################ > > # EX. (8) 132 > > # y=(exp(-x^2)+5-3x)/ > f<- function(x) 4 *x- 5 *((exp(-x^ 2 )+5- 3 *x)/ 2 )-exp(-((exp(-x^ 2 )+5- 3 *x)/ 2 )^ 2 )- > plot(f,-5, 5 ) > uniroot(f,c(-5, 5 )) $root [ 1 ] 1. $f.root [ 1 ] 0. $iter [ 1 ] 4 $init.it [ 1 ] NA

$estim.prec [ 1 ] 6.103516e- > > # Answer: 1. > > ############################################################ > > # EX. (8) 133 > > f<- function(x,y) x^ 2 - 2 xy+ 4 *y^ 2 +x- 5 *y- 1 > fb<- function(x) f(x[ 1 ],x[ 2 ]) > x<- seq(-5, 5 ,len= 100 ) > y<- seq(-5, 5 ,len= 100 ) > fz<- outer(x,y,f) > persp(x,y,fz) > image(x,y,fz) > contour(x,y,fz,add=T,labcex=1.3) > optim(c(-2, 2 ),fb) $par [ 1 ] 0.1665076 0. $value [ 1 ] -2. $counts function gradient 69 NA $convergence [ 1 ] 0 $message NULL > > # Answer: -2. > > ############################################################ > > # EX. (8) 134 > > f<- function(x,y) x^ 2 + 2 xy+y^ 2 +x > g<- function(x,y) (x+ 1 )^ 2 +(y- 1 )^ 2 > x<- seq(-10, 10 ,len= 201 ) > y<- seq(-10, 10 ,len= 201 ) > fz<- outer(x,y,f) > gz<- outer(x,y,g) > contour(x,y,fz,level= 0 ) > contour(x,y,gz,level= 1 ,add=T) > > # Answer: 4 > > ############################################################ > > # EX. (8) 135 > > f<- function(x,y) x^ 2 + 2 xy+y^ 2 +x > g<- function(x,y) (x- 1 )^ 2 +(y- 1 )^ 2 > x<- seq(-10, 10 ,len= 201 ) > y<- seq(-10, 10 ,len= 201 ) > fz<- outer(x,y,f) > gz<- outer(x,y,g) > contour(x,y,fz,level= 0 )