Rectangle approximation, trapezoidal law, Simpson's law, etc. are examples of the divisional quadrature method for numerically obtaining the integral. In the rectangle approximation, the sum of the rectangles obtained by multiplying the value $ f (x_i) $ at a certain point $ x_i $ by the width $ h $ is approximated as the integral value.
Solve the above equation numerically using rectangular approximation.
Rectangle approximation, trapezoidal law, Simpson's law, etc. are examples of the divisional quadrature method for numerically obtaining the integral. According to the trapezoidal rule, the width $ by $ f (x_i) $ and $ f (x_ {i-1}) $ at a certain point $ x_i $ and the point before it $ x_ {i-1} $ </ sub> The sum of the trapezoids of h $ is approximated as the integral value.
Solve the above equation numerically using the trapezoidal law.
Rectangle approximation, trapezoidal law, Simpson's law, etc. are examples of the divisional quadrature method for numerically obtaining the integral. According to Simpson's law, a quadratic function that passes through a certain point $ x_i $, a point before it $ x_ {i-1} $, and a point after it $ x_ {i + 1} $ is derived, and its $ f (x_ { i-1}) Integral value from $ to $ f (x_ {i + 1}) $ $ h (f (x_ {i + 1}) + 4f (x_i) + f (x_ {i-1})) Approximate the sum of / 3 $ as the integral value.
Solve the above equation numerically using Simpson's law.
If you enter the integer $ n $, create a function that returns the number of prime numbers less than or equal to $ n $. Also explain the algorithm.
However,
And.
n = 10
4
n = 100
25
n = 1000
168
n = 10000
1229
n = 100000
9592
There are two grid points $ P = (x_1, y_1) $, $ Q = (x_2, y_2) $ on the Euclidean plane. Create a function on the line segment $ PQ $ to calculate how many grid points exist in addition to $ P $ and $ Q $. Also explain the algorithm.
However,
And.
[Hint] You can reduce to the problem of finding the greatest common divisor. It can be solved efficiently by "Euclidean algorithm". </ font>
x1 = -2
y1 = -9
x2 = 6
y2 = 7
7
#Illustrated and confirmed
%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([x1, x2], [y1, y2])
ax.set_xticks(range(x1, x2 + 1, 1))
ax.set_yticks(range(y1, y2 + 1, 1))
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid()
x1 = -42
y1 = -65
x2 = 62
y2 = -91
25
x1 = 908
y1 = -307
x2 = -86
y2 = -679
0
x1 = -6326
y1 = 3211
x2 = 7048
y2 = 5822
0
x1 = -9675
y1 = -2803
x2 = 3828
y2 = -6349
2
import random
x1 = random.randint(-1000000, 1000000)
y1 = random.randint(-1000000, 1000000)
x2 = random.randint(-1000000, 1000000)
y2 = random.randint(-1000000, 1000000)
print("x1 = ", x1)
print("y1 = ", y1)
print("x2 = ", x2)
print("y2 = ", y2)
Recommended Posts