Informatics2-2018/Lab11

A MathWikiből
(Változatok közti eltérés)
(Új oldal, tartalma: „=Exercises= ==Introduction== Some exercises to bet used to numpy # Make a vector of length 10 with elements all zero! Then modify its 4th element to 1 ''(zeros)'' # Ma…”)
 
(Introduction)
 
(egy szerkesztő 2 közbeeső változata nincs mutatva)
1. sor: 1. sor:
 +
 +
 
=Exercises=
 
=Exercises=
  
 
==Introduction==
 
==Introduction==
Some exercises to bet used to numpy
+
Some exercises to get used to numpy
 
# Make a vector of length 10 with elements all zero! Then modify its 4th element to 1 ''(zeros)''
 
# Make a vector of length 10 with elements all zero! Then modify its 4th element to 1 ''(zeros)''
 
# Make a 3-by-3 matrix with elements ranging from 0 up to 8 ''(reshape)''
 
# Make a 3-by-3 matrix with elements ranging from 0 up to 8 ''(reshape)''
# Make a random vector of length 30 containing random number between 0 to 1! Calculate its range and standard deviation! ''(rand, mean, std)''
+
# Make a random vector of length 30 containing random number between 0 to 1! Calculate its average and standard deviation! ''(rand, mean, std)''
 
## Make a random vector of the same length with elements between -3 and 2!
 
## Make a random vector of the same length with elements between -3 and 2!
 
# Make a random unit vector in 5 dimensions! First make a random vector in 5 dimensions and then normalize it to unit length!
 
# Make a random unit vector in 5 dimensions! First make a random vector in 5 dimensions and then normalize it to unit length!
 +
 
==Monte-Carlo==
 
==Monte-Carlo==
 
Generate 500000 random points in the rectangle <math>[0,2]\times[0,4]</math>. Count how many of the points <math>(x,y)</math> have the property that <math>x^2>y</math>. Use this to approximate the integral <math>\int_0^2x^2 d x</math> Like in the end of the lecture.
 
Generate 500000 random points in the rectangle <math>[0,2]\times[0,4]</math>. Count how many of the points <math>(x,y)</math> have the property that <math>x^2>y</math>. Use this to approximate the integral <math>\int_0^2x^2 d x</math> Like in the end of the lecture.
22. sor: 25. sor:
 
Plot the function <math>\sin(x)</math> and its derivative on the interval <math>[-\pi, \pi]</math>.
 
Plot the function <math>\sin(x)</math> and its derivative on the interval <math>[-\pi, \pi]</math>.
 
Calculate the derivative with [https://en.wikipedia.org/wiki/Finite_difference finite difference] method!
 
Calculate the derivative with [https://en.wikipedia.org/wiki/Finite_difference finite difference] method!
 +
 +
[[Informatics2-2018/Lab10|previous]] [[Informatics2-2018|up]] [[Informatics2-2018/Lab12|next]]

A lap jelenlegi, 2018. május 10., 11:23-kori változata


Tartalomjegyzék

Exercises

Introduction

Some exercises to get used to numpy

  1. Make a vector of length 10 with elements all zero! Then modify its 4th element to 1 (zeros)
  2. Make a 3-by-3 matrix with elements ranging from 0 up to 8 (reshape)
  3. Make a random vector of length 30 containing random number between 0 to 1! Calculate its average and standard deviation! (rand, mean, std)
    1. Make a random vector of the same length with elements between -3 and 2!
  4. Make a random unit vector in 5 dimensions! First make a random vector in 5 dimensions and then normalize it to unit length!

Monte-Carlo

Generate 500000 random points in the rectangle [0,2]\times[0,4]. Count how many of the points (x,y) have the property that x2 > y. Use this to approximate the integral \int_0^2x^2 d x Like in the end of the lecture.

Numeric integral

Estimate the integral of e^{-x^2} on the interval [ − 2,5] with the left Riemann sum!

Gradient descent

Let's have a vector-to-scalar function f(x,y) = x2 + y2. Starting from (x0,y0) = ( − 1, − 1) we will wind the minimum of the function. A gradient step is when you subtract the \nabla f(x,y)\cdot \epsilon from the (x,y) point. If you do this for small ε many times then the point will converge a point where you cannot increase the function value any more, i.e. the gradient is zero. This way you can find the minimum of the function (it will be (x,y) = (0,0)).

  • Store each step along the way, and plot them with matplotlib!

Numeric derivative

Plot the function sin(x) and its derivative on the interval [ − π,π]. Calculate the derivative with finite difference method!

previous up next

Személyes eszközök