Informatics2-2018/HW8
(Ú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) == | ||
− | + | The function should have 3 parameters, two real numbers and one integer: | |
− | a: | + | a: the left-hand-side of the interval |
− | b: | + | b: the right-hand-side of the interval |
− | n: | + | n: the number of uniformly distributed points in the interval |
− | ''a'' < ''b'' | + | ''a'' < ''b'' and ''n'' > 1. |
− | * | + | *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. |
− | * | + | *The partition should contain ''n-2'' uniformly distributed point in <math>[a,b]</math> plus <math>x_0 = a, x_{n-1}=b</math>. |
− | ** | + | **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: <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
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:
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