I tried using Python (3) instead of a scientific calculator

Preparation

The version of Python used is 3.5.1. It is convenient to install numpy ・ (scipy ・) matplotlib ・ sympy as a package, but I will not use it this time. If you installed Python as a package on Linux, you can also install it from the package. Others use pip. (For Windows, start the command prompt powershell with administrator privileges in advance, and install the wheel package with pip (pip install wheel). If the installation with pip fails, https: // pypi Please download the wheel that matches the Python architecture (32/64 bit) / version from .python.org/pypi/wheel/ in advance and then feed it to " pip install ")

Use as a scientific calculator

For Unix, start from the terminal. (python3) In the case of Windows, you can start it from the command prompt / powershell if you pass the path, but you cannot use character strings that are not in Shift-JIS such as seagulls.

First is the basic operation.

>>> 1 + 1
2
>>> 2**3
8
>>> 1/2
0.5
>>> 1 % 2
1
>>> 5 % 3
2
>>> 0.5 * 0.25
0.125

Variable settings / use / deletion are as follows.

>>> x = 5
>>> x ** 2
25
>>> del(x)

Then use various functions.

First, \sin \frac{\pi}{4} I will ask for.

>>> import math as MT
>>> MT.sin(MT.pi * 0.25)
0.7071067811865476

Next, let's ask for 610 !.

n! = \prod_{k=1}^n k = \prod_{k=2}^n k\qquad(n \geq 2)

Take the common logarithm on both sides of

\log_{10} n! = \sum_{k=2}^n \log_{10} k

Substitute $ n = 610 $

\log_{10} 610! = \sum_{k=2}^610 \log_{10} k

If you find 610! As it is, the number of digits will be dangerous, so find it with the coefficient of $ a \ times 10 ^ b \ quad (1 \ leq a <10 \ wedge b \ in \ mathbb {Z}) $.

$610! = a \times 10^b $

Take the common logarithm on both sides of

\log_{10} 610! =\log_{10} a + b

From $ 0 \ leq \ log_ {10} a <1 \ wedge b \ in \ mathbb {Z} $

\begin{cases} \log_{10} a & = \log_{10} 610! - \lfloor\log_{10} 610!\rfloor\newline b & = \lfloor\log_{10} 610!\rfloor \end{cases}

That is,

\begin{cases} a & = 10^{\log_{10} 610! - \lfloor\log_{10} 610!\rfloor}\newline b & = \lfloor\log_{10} 610!\rfloor \end{cases}

It will be.

Relation: https://pbs.twimg.com/media/Cb4JVdcUEAANma0.jpg

If you write this down in Python, it will look like this:

>>> val = 0
>>> for i in range(2,611):
	val += MT.log10(i)

	
>>> print("610! = ", 10 ** (val - MT.floor(val)), "×10^", MT.floor(val), sep = "")
610! = 8.382616099017579×10^1435

Wow ~ McDonald's Ripoff ~ (Stick reading)

numpy, scipy, sympy, matplotlib

With numpy and scipy, you can do more advanced things such as matrix and vector operations. (e.g. numpy.array) In addition, sympy can transform variable expressions and solve equations. (e.g. sympy.symbols) matplotlib can draw graphs. That is, you can take away the work of gnuplot.

Recommended Posts

I tried using Python (3) instead of a scientific calculator
I tried to make a regular expression of "amount" using Python
I tried to make a regular expression of "time" using Python
I tried to make a regular expression of "date" using Python
[Python] I tried using OpenPose
[Python] I tried running a local server using flask
I tried drawing a pseudo fractal figure using Python
I made a Line-bot using Python!
I tried using GrabCut of OpenCV
[Python] I tried using YOLO v3
[Python] I tried collecting data using the API of wikipedia
I tried to make a stopwatch using tkinter in python
I tried a stochastic simulation of a bingo game with Python
I tried to get a database of horse racing using Pandas
I tried playing a ○ ✕ game using TensorFlow
I tried drawing a line using turtle
I tried using Bayesian Optimization in Python
I tried to create a list of prime numbers with python
I tried using UnityCloudBuild API from Python
I tried a functional language with Python
I tried to make a todo application using bottle with python
I tried using pipenv, so a memo
I tried 3D detection of a car
I tried to perform a cluster analysis of customers using purchasing data
I tried to create a sample to access Salesforce using Python and Bottle
I tried to implement a card game of playing cards in Python
[Python / DynamoDB / boto3] List of operations I tried
I tried hundreds of millions of SQLite with python
vprof --I tried using the profiler for Python
I tried web scraping using python and selenium
I tried playing a typing game in Python
[Memo] I tried a pivot table in Python
I tried using Pythonect, a dataflow programming language.
I tried using the Datetime module by Python
I tried adding a Python3 module in C
I tried running alembic, a Python migration tool
I tried using the image filter of OpenCV
I tried using a database (sqlite3) with kivy
I tried to make a ○ ✕ game using TensorFlow
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using Summpy
I tried Python> autopep8
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
A super introduction to Django by Python beginners! Part 2 I tried using the convenient functions of the template
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq