Nice to meet you, this is MatLaser! This is the first post of Qiita to commemorate, thank you! I usually use Python for research, but recently I've become interested in various technologies and am studying little by little. I've always wanted to do this post once, and GW has time, so I wrote it as a good opportunity. Due to lack of technology and knowledge, I think that there are inefficient coding and misunderstandings, but since it is written for beginners to output, I hope you can see it with warm eyes.
Please refer to the pdf of the questions and answers here. In this article as well, we will basically code according to how to solve the answer.
Problem Answer 1,4,5,6 Answer 2,3
(1) You just use the cosine theorem.
(2) By properly setting the coordinates of the three points A, B, and C, the existence of the variable $ s $ can be set only to the $ y $ coordinates of the point P, which makes the calculation a little easier.
Below is the answer image.
Let's code.
1.py
#Initial conditions
ab = 1
ac = 1
bc = 0.5
import numpy as np
# (1)
#Cosine theorem
cos_theta = (ab**2 + ac**2 - bc**2) / (2 * ab * ac)
sin_theta = np.sqrt(1 - cos_theta**2)
print(cos_theta, sin_theta) # 0.875 0.484 = 7/8 (√15)/8
# (2)
# func = AP^2 + BP^2 + CP^2
def func(s):
return 25/32 + 15/64 * ((3 * (s - 2/3)**2) + 2/3)
lis = [] #A list that stores the value of the variable s and the func at that time as a tuple.
# 0<s<1 to 0.Change by 01 and search all
for s in np.arange(0,1,0.01):
value = func(s)
lis.append((s, value))
print(lis)
# min_Sort by value and output the first element
lis_sort = sorted(lis, key=lambda values: values[1])
print(lis_sort[0]) # (s, min_value) = (0.67, 0.9375)
(1) You can obediently find the intersection of straight lines L and M and substitute it for circle C.
(2) The subject is satisfied when the distance between the center of the circle C and the straight line L is smaller than the radius (a) of the circle C.
(3) Similar to (2), you can find the number of shared stores by comparing the distance between the point and the straight line and the radius of the circle C, and then just look up honestly. This only changes the inequality sign in (2), so I will omit it.
Below is the answer image.
Let's code.
2.py
import sympy
x = sympy.Symbol('x')
y = sympy.Symbol('y')
a = sympy.Symbol('a')
# (1)
expr1 = -4 * x + 3 * y + a
expr2 = 3 * x + 4 * y - 7 * a
d = sympy.solve([expr1, expr2], [x,y])
# print(d) #The intersection of straight lines L and M(a, a)I understand
#In circle C (a,Substitute a)
sympy.var('x, y, a')
x = d[x] #Substitute the x coordinate of the intersection obtained above for x
y = d[y] #Substitute the y coordinate of the intersection obtained above for y
sol = sympy.solve (1 * x**2 - 2 * a * x + y**2 - 4 * y + 4, a)
sympy.init_printing()
print(sol) #Get a list of answers (only 1 this time)
# (2)
#The solution of the inequality sign can be set to the interval type with Interval and the union can be taken, but this time it ends with finding the boundary value from the equation.
dis = abs(6 - 3 * a)/5
# dis^2 = abs(a)Squared on both sides to solve
expr3 = 16 * a**2 + 36 * a - 36
d2 = sympy.solve([expr3])
print(d2) # [{a: -3}, {a: 3/4}]Boundary value where the number of shared stores changes
# (3)
#abridgement
(1) Looking at the problem statement, I think there are the following three solutions that come to mind. ・ Mathematical induction ・ Derivation of inequalities by formula transformation -Functionalization: As $ f (n) = 3 ^ n- (2 ^ n + n ^ 2 + 8) $, it is shown that $ n ≥ 3 $ and $ f (n)> 0 $. The answer uses mathematical induction, but from the perspective of solving it by programming, I think it is the easiest to make it a function.
(2) Since (1) shows that $ n ≧ 3 $ and $ f (n)> 0 $, at least $ n <3 $ is required for $ f (n) ≦ 0 $. Must be. Also, since $ n $ is a positive integer this time, we can see that $ n = 1,2 $ is a candidate solution. Once you know this, all you have to do is actually substitute and see if the subject holds.
(3) Since $ a, b, n $ are all 0 or more, the equation $ 2 ^ n + n ^ 2 + 8 = 3 ^ n + an + b $ holds for $ n = 1 $ or $ 2. $ Only.
Below is the answer image.
Let's code.
3.py
# (1)
import math
# f(n)
def func(n):
return 3**n - (2**n + n**2 + 8)
# f'(n)
def func_p1(n):
return 3**n * math.log(3) - (2**n * math.log(2) + 2 * n)
# f''(n)
def func_p2(n):
return 3**n * math.log(3)**2 - 2**n * math.log(2)**2
# print(func_p2(3)) # 28.74 ← 0 or more
#And n>3 at func_p2(n) >0 (∵ 3**n >> 2**n)
#Therefore n>3 at func_p1(n)Is monotonously increasing...(1)
#Also print(func_p1(3)) # 18.11 ← 0 or more...(2)
# (1),(2)More n>3 at func(n)Also monotonously increasing...(3)
#Further print(func(3)) #2 ← 0 or more...(4)
#Therefore,(3),(4)More n>=3 at func(n) > 0
# Q.E.D
# (2)
print(func(1), func(2)) # -8 -7 Therefore f(n) <0, therefore n that satisfies the subject is 1,2
# (3)
lis = [] #Solution list
for a in range(9): # n,a,b >=From 0, a,b is 0~8 is enough
for b in range(9):
# n=When 1
jouken1 = a + b # joken1 = 8
# n=2 o'clock
jouken2 = 2 * a + b # joken2 = 7
if jouken1 == 8:
lis.append((a,b,1))
elif jouken2 == 7:
lis.append((a,b,2))
else:
continue
print(lis)
#[(0, 7, 2), (0, 8, 1), (1, 5, 2), (1, 7, 1), (2, 3, 2), (2, 6, 1), (3, 1, 2), (3, 5, 1), (4, 4, 1), (5, 3, 1), (6, 2, 1), (7, 1, 1), (8, 0, 1)]
This time I would like to end here. I might do the rest of the problems if I'm too free to die ww I solved simultaneous equations using Python for the first time, which is wonderful. You can really do anything, Python is amazing! If you come up with something you want to try again or something that looks interesting, I will do it loosely.
Thank you for visiting.
Recommended Posts