After all, there was a predecessor (maybe there are others). **Great! ** **
It seems that you can bring in the following, but at the moment it seems that ** Python interpreter cannot be brought in </ font> **, so be careful. For developers, I think the claim that the development environment is like a pencil is ** not understandable **. ** * Never bring anything other than what is permitted! </ font> **
*Black pencil(Limited to H, F, HB. It is not possible to print Japanese poems, sayings, etc.), Pencil cap.
*mechanical pencil(Only available for memos and calculations, limited to black cores.)
*Plastic eraser
*Pencil sharpener(Electric, large and knives are not allowed.)
*clock(Those that have functions such as dictionaries, calculators, and terminals, those that are difficult to determine whether or not they have such functions, those that make a second hand sound, kitchen timers, and large ones are not allowed.)
*Glasses, handkerchiefs, eye drops, tissue paper(Only the contents are taken out from the bag or box.)
** Only the first question [1] of the 2017 National Center Test for University Admissions Math II / Math B **.
Why I chose this question: "I think I can win this question in Python."
** Question 1 (Mandatory question) (Score 30) **
[1] Simultaneous equations
\left\{
\begin{array}{ll}
cos \, 2\alpha + cos \, 2\beta = \frac{4}{15} \quad\quad\quad\,\,\,\,...(1) \\
cos \, \alpha \, \, cos \, \beta = -\frac{2\sqrt{15}}{15} \quad\quad\quad\,\,\,\,\,...(2)
\end{array}
\right.
think of. However, it is $ 0 \ leqq \ alpha \ leqq \ pi, \ quad 0 \ leqq \ beta \ leqq \ pi $, $ \ alpha <\ beta $ and
|cos \, \alpha| \geqq |cos \, \beta| \quad\quad\quad\quad\quad\quad...(3)
And. At this time, let's find the values of $ cos , \ alpha $ and $ cos , \ beta $.
Using the double-angle formula, from (1)
cos^2 \alpha + cos^2 \beta = \frac{[Ai]}{[Ue]}
Is obtained. Also, from (2),
cos^2 \alpha \, \, cos^2 \beta = \frac{[Oh]}{15}
Is. Therefore, using condition (3)
cos^2 \alpha = \frac{[Mosquito]}{[Ki]} \quad, \quad\quad cos^2 \beta = \frac{[Ku]}{[Ke]}
Is. Therefore, from the condition of (2) $ 0 \ leqq \ alpha \ leqq \ pi, \ quad 0 \ leqq \ beta \ leqq \ pi, \ quad \ alpha <\ beta $
cos \, \alpha = \frac{[Ko]\sqrt{[Service]}}{[Shi]} \quad, \quad\quad cos \, \beta = \frac{[Su]\sqrt{[Se]}}{[So]}
Is.
Given the total amount of the problem, I think this problem is tough unless it is solved within 6 or 7 minutes. With that in mind, the victory conditions on the "Python + me" side are set as follows.
The environment prepared for reference is as follows.
(The entire completed code will be posted at the end of this article.)
I'm saying that I don't understand the double-angle formula, so Suddenly, it is calculated from the last $ cos \ alpha, cos \ beta $. You should be able to do it with Python and SymPy. First, install SymPy!
pip install sympy
Let's solve it all at once!
from sympy import symbols, expand, cos, Rational, sqrt, solve
#Symbol definition. In this problem, α and β are treated as symbols of a and b, respectively.
a, b = symbols('a b')
# (1)When(2)Each formula is f1= 0, f2 = 0Whenなるような関数f1, f2Whenして定義。
#After this, cos(a)And cos(b)Since we solve the simultaneous equations with respect to(1)Deploy(expand)I will do it.
f1 = expand(cos(2*a) + cos(2*b) - Rational(4, 15), trig = True)
f2 = cos(a) * cos(b) + 2 * sqrt(15) / 15
#Simultaneous equations of f1 and f2, cos(a)And cos(b)Solve for(solve)。
answers = solve([f1, f2], [cos(a), cos(b)])
At this point, ʻanswers` should have some solutions, but find the one you want from the conditions.
$ 0 \ leqq \ alpha \ leqq \ pi, \ quad 0 \ leqq \ beta \ leqq \ pi $, with the condition $ \ alpha <\ beta $
In the range of $ 0 \ leqq \ theta \ leqq \ pi $, $ cos \ theta $ becomes smaller as $ \ theta $ becomes larger, so
Find a solution that is $ cos \ alpha> cos \ beta
Since the absolute value has come out, I will add it to ʻimport`.
from sympy import symbols, expand, cos, Rational, sqrt, solve, Abs
After that, we will search for the set of solutions that meet the conditions from the list of sets of solutions contained in ʻanswers. In the ʻif
statement, the condition is simply made into a conditional expression.
# 0 <= a <= π, 0 <= b <=In π, a,The larger b is cos(a), cos(b)The value of becomes smaller.
# a <b, so cos(a) > cos(b)Look for something that will be.
#And,(3)Find the one that meets the conditions of.
for cos_a, cos_b in answers:
if cos_a > cos_b and Abs(cos_a) >= Abs(cos_b):
break
This will give you $ cos \ alpha, cos \ beta $.
#Target cos(a)And cos(b)I got it, so I will display it([Ko][Service][Shi][Su][Se][So]Answer)。
print("[Kosashi] -> {}, [Suseso] -> {}".format(cos_a, cos_b))
Just ask for $ cos ^ 2 \ alpha, cos ^ 2 \ beta $ and $ cos ^ 2 \ alpha + cos ^ 2 \ beta $, $ cos ^ 2 \ alpha , , cos ^ 2 \ beta $ Since $ cos \ alpha and cos \ beta $ have already been calculated, they can be calculated simply by calculating.
# cos(a)And cos(b)Find the square of each.
squared_cos_a = cos_a ** 2
squared_cos_b = cos_b ** 2
# cos(a)Squared and cos(b)Shows the square of([Mosquito][Ki][Ku][Ke]Answer)。
print("[Oyster] -> {}, [Kuke] -> {}".format(squared_cos_a, squared_cos_b))
# cos(a)Squared and cos(b)Also displays the sum and product of the squares of([A][I][C][D][Oh]Answer)。
print("[Aiue] -> {}".format(squared_cos_a + squared_cos_b))
print("[Oh] -> {}".format(squared_cos_a * squared_cos_b))
(The entire completed code will be posted at the end of this article.)
The time it takes to execute the completed Python code (the time it takes to find all the solutions) is In my environment, it was ** less than 400ms ** (just the time since the code started running).
However, the time required for coding was ** 14 minutes 41 seconds 524 **, so It was a complete defeat on the Python side (or rather me), ** overwhelming defeat **. .. ..
(Since this article itself started writing after the game was settled, the writing time of the article is not included.)
from sympy import symbols, expand, cos, Rational, sqrt, solve, Abs
import time
#I want to output the time it took to solve, so remember the first time.
offset = time.time()
#Symbol definition. In this problem, α and β are treated as symbols of a and b, respectively.
a, b = symbols('a b')
# (1)When(2)Each formula is f1= 0, f2 = 0Whenなるような関数f1, f2Whenして定義。
#After this, cos(a)And cos(b)Since we solve the simultaneous equations with respect to(1)Deploy(expand)I will do it.
f1 = expand(cos(2*a) + cos(2*b) - Rational(4, 15), trig = True)
f2 = cos(a) * cos(b) + 2 * sqrt(15) / 15
#Simultaneous equations of f1 and f2, cos(a)And cos(b)Solve for(solve)。
answers = solve([f1, f2], [cos(a), cos(b)])
# 0 <= a <= π, 0 <= b <=In π, a,The larger b is cos(a), cos(b)The value of becomes smaller.
# a <b, so cos(a) > cos(b)Look for something that will be.
#And,(3)Find the one that meets the conditions of.
for cos_a, cos_b in answers:
if cos_a > cos_b and Abs(cos_a) >= Abs(cos_b):
break
#Target cos(a)And cos(b)I got it, so I will display it([Ko][Service][Shi][Su][Se][So]Answer)。
print("[Kosashi] -> {}, [Suseso] -> {}".format(cos_a, cos_b))
# cos(a)And cos(b)Find the square of each.
squared_cos_a = cos_a ** 2
squared_cos_b = cos_b ** 2
# cos(a)Squared and cos(b)Shows the square of([Mosquito][Ki][Ku][Ke]Answer)。
print("[Oyster] -> {}, [Kuke] -> {}".format(squared_cos_a, squared_cos_b))
# cos(a)Squared and cos(b)Also displays the sum and product of the squares of([A][I][C][D][Oh]Answer)。
print("[Aiue] -> {}".format(squared_cos_a + squared_cos_b))
print("[Oh] -> {}".format(squared_cos_a * squared_cos_b))
#Shows the time it took to solve.
elapsed = time.time() - offset
print('Time taken to solve: {0:.4f}millisecond'.format((elapsed * 1000)))
Recommended Posts