Getting Started with Python

Python
https://www.runoob.com/python/python-tutorial.html
# Python2
https://www.runoob.com/manual/pythontutorial/docs/html/
# Python3
https://www.runoob.com/python3/python3-tutorial.html

install Python, Numpy, Scipy, and Matplotlib  https://blog.youkuaiyun.com/sh20100621/article/details/91350577

matplotlib https://blog.youkuaiyun.com/sh20100621/article/details/91351434

numpy & scipy https://blog.youkuaiyun.com/sh20100621/article/details/80848509

Download and installation:
Refer to 最实用windows 下python+numpy安装_包包蔡的博客-优快云博客
Python27 : Windows x86 MSI installer for Windows XP
Python36 : Windows x86-64 executable installer for Windows 10
1. download Python27 from https://www.python.org/downloads/
python-2.7.15.msi
* Install and Add Python.exe to Path
2. download numpy for Python27 from https://pypi.python.org/pypi/numpy
numpy-1.14.5-cp27-none-win32.whl

download scipy for Python 27 from https://pypi.org/project/scipy/
* install numpy and scipy
3. run cmd
d:\>notepad install.bat
edit
: install python27

python -m pip install --upgrade pip
pip install numpy-1.14.5-cp27-none-win32.whl

pip install scipy-1.1.0-cp27-none-win32.whl

python -m pip install matplotlib

:: python -m pip install -U pip setuptools
:: pip install numpy scipy matplotlib
:: install python35
:: python-3.5.3.exe
:: python-3.5.3-amd64.exe
:: numpy-1.14.5-cp35-none-win32.whl
:: numpy-1.14.5-cp35-none-win_amd64.whl
:: scipy-1.1.0-cp35-none-win32.whl
:: scipy-1.1.0-cp35-none-win_amd64.whl
::
:: python36
:: python-3.6.5.exe
:: python-3.6.5-amd64.exe
:: numpy-1.14.5-cp36-none-win32.whl
:: numpy-1.14.5-cp36-none-win_amd64.whl
:: scipy-1.1.0-cp36-none-win32.whl
:: scipy-1.1.0-cp36-none-win_amd64.whl
save
d:\>install
d:\>Python
>>>import numpy as np
>>>np.random.rand(4,4)

>>>import scipy

>>>import matplotlib
>>>exit()

Tutorial:
* http://www.runoob.com/python/python-tutorial.html

# solve systerm of nonlinear equations by using root, fsolve

# sample.py

# Refer to https://blog.youkuaiyun.com/your_answer/article/details/79170728
from scipy.optimize import root, fsolve, leastsq
import numpy as np
from matplotlib import pyplot as plt

def f1(x):
      return np.array([2*x[0]**2+3*x[1]-3*x[2]**3-7,
                    x[0]+4*x[1]**2+8*x[2]-10,
                    x[0]-2*x[1]**3-2*x[2]**2+1])
#
sol_root = root(f1,[0,0,0])
sol_fsolve = fsolve(f1,[0,0,0])
print(sol_root)
print(sol_fsolve)
#
def f2(x):
      return 2*np.sin(x)-x+2
#
x=np.linspace(-5,5,num=100)
y=f2(x)
root1=fsolve(f2,[1])
root2=root(f2,[1])
print(root1)
print(root2)
plt.plot(x,y,'r')
plt.show()

# end of sample.py

# https://blog.youkuaiyun.com/unixtch/article/details/78545382
# https://blog.youkuaiyun.com/u011702002/article/details/78078010
from scipy.optimize import fsolve, leastsq
from math import sin,cos
def f(x):
    x0 = float(x[0])
    x1 = float(x[1])
    x2 = float(x[2])
    return [
        5*x1+3,
        4*x0*x0 - 2*sin(x1*x2),
        x1*x2-1.5
        ]
x0 = [1,1,1]
result = fsolve(f,x0)
print("===================")
print()
print("求解函数名称:",fsolve.__name__)
print("解:",result)
print("各向量值:",f(result))
#拟合函数来求解
h = leastsq(f,x0)
print("===================")
print()
print("求解函数名称:",leastsq.__name__)
print("解:",h[0])
print("各向量的值:",f(h[0]))


常见错误:

o IndentationError:expected an indented block
* https://blog.youkuaiyun.com/gaokao2011/article/details/76209020

# sample.py
str = "Hello World!"
print (str)
import math
x = math.pi

print(x)
arg1 = 1
arg2 = 2
def sum(arg1,arg2):
 total = arg1 + arg2
 return total
y = sum(arg1,arg2)
print(y)
def sub(arg1,arg2):
 total = arg1 - arg2
 return total
z = sub(arg1,arg2)
print(z)
# end of sample.py
# How to use function of different Python file
# https://www.cnblogs.com/jiuyigirl/p/7146223.html
# a.py
def sum(arg1, arg2):
    total = arg1 + arg2
    return total
# end of a.py
# b.py
import a
x = a.sum(1,2)
print '1 + 2 =', x

# end of b.py

# ch70.py
sigma_x = -70
sigma_y = 0
tau_x = 50
import ch7
z = ch7.result(sigma_x, sigma_y, tau_x)
print z
print 'sigma1 = ', z[0]
print 'sigma2 = ', 0
print 'sigma3 = ', z[1]
print 'alpha0 = ', z[2]
print 'tau_max = ', z[3]
# end of ch70.py
# ch7.py
import math
def result(sigma_x, sigma_y, tau_x):
    OC = 0.5 * (sigma_x + sigma_y)
    CH = 0.5 * (sigma_x - sigma_y)
    radius = (CH**2 + tau_x**2)**0.5     
    alpha0 = 0.5 * math.atan(-tau_x/CH)
    z = [OC + radius, OC - radius, alpha0 * 180/math.pi, radius]
    return z

# end of ch7.py

# ch3.py
import math
def Wp(diameter, alpha):
    return math.pi * ( diameter ** 3.0 ) * (1.0 - alpha ** 4) / 16
def Diameter(Tmax, tau0):
    fenzi = 16.0 * Tmax
    fenmu = math.pi * tau0
    return [fenzi, fenmu, (fenzi/fenmu) ** (1.0 / 3.0)]
# end of ch3.py
# ch30.py
d0 = 24.0e-3
d1 = 18.0e-3
alpha = d1/d0
T_max = 1.5e2
import ch3
Tau_max = T_max / ch3.Wp(d0, alpha)
print Tau_max,'Pa'
print Tau_max/1e6,'MPa'
T_max = 1.5e3
tau0 = 50.0e6
diameter_min = ch3.Diameter(T_max, tau0)
print diameter_min[2], 'm'
print diameter_min[2] * 1.0e3, 'mm'
# end of ch30.py
   
 

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值