I tried the study supplement as a review of high school math and it was amazing. In particular, Professor Yoshiaki Sakai's class and Professor Masao Seki's class in English are at a level that would have changed my life if I had taken them in high school. (Actually, I only took these two courses.) However, it is said that time cannot be rewound (I think I can do it personally ...), so I would like to study high school mathematics by dropping it into a program.
Regarding study supplements, it has nothing to do with studying, and I would like to see a beautiful teacher's chemistry class, but when I was in high school I was only interested in physics, and I didn't study chemistry at all. .. .. If you have the physical strength to study a new subject unrelated to work, I will take a look.
$ \ displaystyle \ text {①} 0 <a <1 when a \ left (x + 2 \ right) <\ frac {\ left (3-x \ right) ^ {2}} {2} $
$ \ displaystyle \ text {②} 1 When <a \ frac {\ left (3-x \ right) ^ {2}} {2} <a \ left (x + 2 \ right) $
$ \ text {In addition, it is described in the condition as a positive integer that is not} a \ neq 1 \ text {from the problem statement. } $
Please learn about the transformation of the above formula in the study supplement course.
Illustrate the graph of $ \ text {. } $
$ \ left (\ text {Formula transformation is not the subject of this article, so I've omitted it a bit} \ right) $
The execution environment is as follows.
First, build a program creation environment.
python -m venv math
.\math\Scripts\activate
I don't use anaconda, ipthon, or jupyter unless it's necessary. I know it's very convenient, but for some reason this method is the most suitable.
pip list
Package Version ---------- ------- pip 19.0.3 setuptools 40.8.0 You are using pip version 19.0.3, however version 19.3.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
python -m pip install --upgrade pip
pip install matplotlib
pip install sympy
pip list
Package Version ---------- ------- cycler 0.10.0 kiwisolver 1.1.0 matplotlib 3.1.1 mpmath 1.1.0 numpy 1.17.3 pip 19.3.1 pyparsing 2.4.4 python-dateutil 2.8.1 setuptools 40.8.0 six 1.13.0 sympy 1.4
For now, you're ready to program.
First of all
sample01.py
from sympy import Symbol
from sympy.plotting import plot
import numpy as np
import matplotlib.pyplot as plt
#Define variable x
x = Symbol('x')
#Define a given formula
f_x = (x-3)**2
#Since the axis of the formula is 3,-Draw a range of 2-8
x_val = np.linspace(-2, 8, 100)
# f_Store x values in a list
y_val = []
for x_data in x_val :
y_val.append(f_x.subs({x:x_data}))
# y_Convert val to numpy format
y_val = np.array(y_val)
#Check variable information
print("x_type of val: ")
print(type(x_val))
print("y_type of val: ")
print(type(y_val))
print("x_Number of elements in val: ")
print(len(x_val))
print("y_Number of elements in val: ")
print(len(y_val))
#Creating a graphing area
fig = plt.figure()
#Drawing a graph
plt.plot(x_val, y_val, label="f_x")
#Specifying and saving the file name of the graph
outputFileName = "sample01.png "
plt.savefig(outputFileName)
plt.close()
type of x_val: <class 'numpy.ndarray'> type of y_val: <class 'numpy.ndarray'> Number of elements in x_val 100 Number of elements in y_val 100
I know it's a forced code, but at this point (as of November 10, 2019), this is all I can do. If anyone knows how to write beautifully, please give me some advice.
plot(f_x, (x,-2,8))
It's easy to illustrate with, but the plt.savefig function doesn't work, right? So, knowing that it is dirty code, if you write a program within the knowledge you know, it will be the above content. .. ..
See below
I would like to summarize the python grammar and matplotlib formatting on another page.
Recommended Posts