Informatics2-2018/HW8

A MathWikiből
(Változatok közti eltérés)
(Új oldal, tartalma: „= numpy Homework= [https://docs.scipy.org/doc/numpy/reference/index.html numpy] Implement the following python functions. The name of the exercise should be the name o…”)
 
 
18. sor: 18. sor:
  
 
== derivative (3p) ==
 
== derivative (3p) ==
A függvény bemenete legyen két valós szám és egy egész szám:
+
The function should have 3 parameters, two real numbers and one integer:
 
    
 
    
   a: tartomány eleje
+
   a: the left-hand-side of the interval
   b: tartomány vége
+
   b: the right-hand-side of the interval
   n: hány osztópont legyen véletlenszerűen , beleértve a végpontokat
+
   n: the number of uniformly distributed points in the interval
  
''a'' < ''b'' és ''n'' > 1.
+
''a'' < ''b'' and ''n'' > 1.
  
*Kimenete egy ''n-1'' hosszú numpy vektor legyen, ami a <math>\sin(x)/x</math> függvény numerikus deriváltját tartalmazza.
+
*The output should be a numpy vector of length ''n-1'' containing the numerical derivative of the function <math>\sin(x)/x</math> on the given interval using the random partition.
*Az osztópontok véletlenül helyezkedjenek ez az <math>[a,b]</math> intervallumban, de a végpontok mindenképpen <math>x_0 = a, x_{n-1}=b</math> legyenek.
+
*The partition should contain ''n-2'' uniformly distributed point in <math>[a,b]</math> plus <math>x_0 = a, x_{n-1}=b</math>.
**véletlen felosztást úgy generálhatunk, ha veszünk ''n-2'' véletlen pontos és sorba rendezzük azokat, majd elé fűzzük ''a''-t és utána ''b''-t.
+
**You can make this partition by making ''n-2'' random points, sort them then add ''a'' to the front and ''b'' to the end.
** ehhez kellhet: <tt>numpy.sort</tt> és <tt>numpy.random.rand</tt>
+
** you might want to use: <tt>numpy.sort</tt> and <tt>numpy.random.rand</tt>
  
 
Remember the (forward) finite difference:
 
Remember the (forward) finite difference:

A lap jelenlegi, 2018. május 14., 23:12-kori változata

Tartalomjegyzék

numpy Homework

numpy

Implement the following python functions. The name of the exercise should be the name of the function. You will need import numpy! On your own computer I recommend Anaconda because it is installed with numpy by default. Mind that you need the 2.7 version. Or you can use the leibniz.

integral (2p)

The function should have 3 parameters, two real numbers and one integer:

  a: the left-hand-side of the interval
  b: the right-hand-side of the interval
  n: the number of equally spaced points in the partition, including a and b

a < b and n > 1.

The output should be a real number: the integral of the function sin(x) / x on the interval [a,b] calculated with the trapezoidal rule.

derivative (3p)

The function should have 3 parameters, two real numbers and one integer:

  a: the left-hand-side of the interval
  b: the right-hand-side of the interval
  n: the number of uniformly distributed points in the interval

a < b and n > 1.

  • The output should be a numpy vector of length n-1 containing the numerical derivative of the function sin(x) / x on the given interval using the random partition.
  • The partition should contain n-2 uniformly distributed point in [a,b] plus x0 = a,xn − 1 = b.
    • You can make this partition by making n-2 random points, sort them then add a to the front and b to the end.
    • you might want to use: numpy.sort and numpy.random.rand

Remember the (forward) finite difference:

{\Delta f}_i = \frac{f(x_{i+1})-f(x_i)}{x_{i+1}-x_i}

Handing-in

Send the exercises as a python code from your math email account to info1hazi@gmail.com

You should attach one python file containing the definition of the required functions without any test code or print command.

The file should be named:

  EN1_HF8_<user account>.py

the subject of the letter should be the same (without the extension). For me example:

  EN1_HF8_borbely.py

Deadline

20th of May, 29:59

Személyes eszközök