# Question 11: Divided quadrature method (rectangular approximation)

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.

# Question 12: Divided quadrature method (trapezoidal rule)

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.

# Question 13: Divisional quadrature method (Simpson's 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.

# Question 14: Eratosthenes sieve

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,

• 1 ≤ n ≤ 106

And.

## Example 14-1

``````n = 10
``````
``````4
``````

## Example 14-2

``````n = 100
``````
``````25
``````

## Example 14-3

``````n = 1000
``````
``````168
``````

## Example 14-4

``````n = 10000
``````
``````1229
``````

## Example 14-5

``````n = 100000
``````
``````9592
``````

# Question 15: Number of grid points

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,

• -106x_1 ≤ 106
• -106x_2 ≤ 106
• -106y_1 ≤ 106
• -106y_2 ≤ 106

And.

[Hint] You can reduce to the problem of finding the greatest common divisor. It can be solved efficiently by "Euclidean algorithm". </ font>

## Example 15-1

``````x1 =  -2
y1 =  -9
x2 =  6
y2 =  7
``````
``````7
``````
``````#Illustrated and confirmed
%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
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()
`````` ## Example 15-2

``````x1 =  -42
y1 =  -65
x2 =  62
y2 =  -91
``````
``````25
``````

## Example 15-3

``````x1 =  908
y1 =  -307
x2 =  -86
y2 =  -679
``````
``````0
``````

## Example 15-4

``````x1 =  -6326
y1 =  3211
x2 =  7048
y2 =  5822
``````
``````0
``````

## Example 15-5

``````x1 =  -9675
y1 =  -2803
x2 =  3828
y2 =  -6349
``````
``````2
``````

## Reference: How to make an example

``````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)
``````