forked from ustcwpz/USTC-CS-Courses-Resource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove some resource and Modify history
- Loading branch information
Showing
2,362 changed files
with
900,233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[数学书籍和习题](https://pan.baidu.com/s/1HRPykNB2x2KdNlPA5m-wuQ), 提取码: 0000 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# [课程主页](http://home.ustc.edu.cn/~weihuang/pde/) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
**<span style="float:right">PB16030899-朱河勤 <br>2018-5-20<span>** | ||
|
||
|
||
# <center> 高斯列主元消元法计算行列式 | ||
>书上p186, 附录1程序11 | ||
# 算法描述 | ||
行序从1到m,当为第i行, 找出第i列第i个数到第m个数中最大值的行k,然后交换行i,k, 然后依次用第i行,将i+1..m行的第i个元素化作0, 最后得到上三角矩阵, 对角线元素相乘就得到行列式 | ||
|
||
# 程序源码 | ||
```python | ||
import numpy as np | ||
def gauss_prior_elimination(A,b=None): | ||
'''using guass elimination,get up_trianglge form of A''' | ||
m,n = A.shape | ||
res = [0]*m if b is None else b | ||
if m!=n:raise Exception("[Error]: matrix is not inversable") | ||
# necessary,otherwise when the dtype of A is int, then it will be wrong | ||
B = np.matrix(A,dtype=float) | ||
for i in range(m-1): | ||
col = abs(B[i:,i]) # note using abs value, return a matrix in (m-i)x1 form | ||
mx = col.max() | ||
if mx==0: raise Exception("[Error]: matrix is not inversable") | ||
pos = i+col.argmax() | ||
if pos != i : B[[pos,i],:] = B[[i,pos],:] # note how to swap cols/rows | ||
#B[i,:] = B[i,:]/mx | ||
#res[i]/=mx | ||
for j in range(i+1,m): | ||
if B[j,i]!=0: | ||
B[j,:] -= B[j,i]/B[i,i] * B[i,:] | ||
res[j] -= res[i]/B[i,i]*res[j] | ||
if b is None:return B | ||
return B,res | ||
|
||
def det(A): | ||
m,n = A.shape | ||
ret=1 | ||
B = gauss_prior_elimination(A) | ||
print(B) | ||
for i in range(m):ret *= B[i,i] | ||
return ret | ||
``` | ||
|
||
# 测试结果 | ||
![](determine.png) |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
######################################################################### | ||
# File : linear_equation.py | ||
# Author: mbinary | ||
# Mail: [email protected] | ||
# Blog: https://mbinary.xyz | ||
# Github: https://github.com/mbinary | ||
# Created Time: 2018-05-20 08:36 | ||
# Description: 书上p186 附录1 程序11 | ||
######################################################################### | ||
|
||
import numpy as np | ||
|
||
def gauss_prior_elimination(A,b=None): | ||
'''using guass elimination,get up_trianglge form of A''' | ||
m,n = A.shape | ||
res = [0]*m if b is None else b | ||
if m!=n:raise Exception("[Error]: matrix is not inversable") | ||
B = np.matrix(A,dtype=float) # necessary,otherwise when the dtype of A is int, then it will be wrong | ||
for i in range(m-1): | ||
col = abs(B[i:,i]) # note using abs value, return a matrix in (m-i)x1 form | ||
mx = col.max() | ||
if mx==0: raise Exception("[Error]: matrix is not inversable") | ||
pos = i+col.argmax() | ||
if pos != i : B[[pos,i],:] = B[[i,pos],:] # note how to swap cols/rows | ||
#B[i,:] = B[i,:]/mx | ||
#res[i]/=mx | ||
for j in range(i+1,m): | ||
if B[j,i]!=0: | ||
B[j,:] -= B[j,i]/B[i,i] * B[i,:] | ||
res[j] -= res[i]/B[i,i]*res[j] | ||
if b is None:return B | ||
return B,res | ||
|
||
def det(A): | ||
m,n = A.shape | ||
ret=1 | ||
B = gauss_prior_elimination(A) | ||
for i in range(m):ret *= B[i,i] | ||
return ret | ||
|
||
def test(A): | ||
print() | ||
print('计算行列式') | ||
print(A) | ||
print('我的结果: det(A) = ',det(A)) | ||
print('函数调用: det(A) = ',np.linalg.det(A)) | ||
if __name__ == '__main__': | ||
A = np.matrix([[10,5,0,0], | ||
[2,2,1,0], | ||
[0,10,0,5], | ||
[0,0,2,1]]) | ||
test(A) | ||
|
||
A = np.matrix([[-6,3,2], | ||
[3,5,1], | ||
[2,1,6]]) | ||
test(A) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
**<span style="float:right">PB16030899-朱河勤 <br>2018-5-20<span>** | ||
|
||
|
||
# <center> 数值积分 | ||
|
||
# 算法描述 | ||
分别用了梯形计算公式 , 辛普森计算公式, 龙贝格计算公式在复化形式(避免龙格现象的出现) | ||
|
||
计算积分的值 | ||
|
||
第一个例子是[0.6,1.8], 区间间隔为0.2,函数值给出,用了梯形与辛普森去求数值积分, | ||
是书上p137习题6 | ||
|
||
第二个例子是求 $\int_{1}^{2} sin(x^4)dx$ (我自己举的例子) | ||
利用了龙贝格数值积分公式来求 | ||
|
||
|
||
# 测试结果 | ||
![](test.png) | ||
|
||
|
||
# 程序源码 | ||
```python | ||
|
||
from math import sin | ||
|
||
import numpy as np | ||
|
||
def mypprint(lst): | ||
for i in lst: | ||
print(('%.4f'%i).ljust(10),end='') | ||
print() | ||
|
||
def trapezoidal(a,b,h,fs): | ||
'''梯形积分公式''' | ||
xs = [i for i in np.arange(a,b+h,h)] | ||
print('x'.ljust(10),end='') | ||
mypprint(xs) | ||
print('fx'.ljust(10),end='') | ||
mypprint(fs) | ||
ret = h*(sum(fs)-fs[0]/2 - fs[-1]/2) | ||
print(ret) | ||
return ret | ||
|
||
|
||
def simpson(a,b,h,fs): | ||
'''辛普森积分公式''' | ||
xs = [i for i in np.arange(a,b+h,h)] | ||
print('x'.ljust(10),end='') | ||
mypprint(xs) | ||
print('fx'.ljust(10),end='') | ||
mypprint(fs) | ||
ret = h/3*(4* sum(fs[1::2])+ 2*sum(fs[2:-1:2]) + fs[0]+fs[-1]) | ||
print(ret) | ||
return ret | ||
|
||
|
||
def romberg(a,b,f,epcilon): | ||
'''romberg(龙贝格) 数值积分''' | ||
h = b-a | ||
lst1=[h*(f(a)+f(b))/2] | ||
mypprint(lst1) | ||
delta = epcilon | ||
k=1 | ||
while delta >= epcilon: | ||
h/=2 | ||
k+=1 | ||
lst2=[] | ||
lst2.append((lst1[0]+h*2*sum(f(a+(2*i-1)*h) for i in range(1,2**(k-2)+1)))/2) | ||
for j in range(0,k-1): | ||
lst2.append(lst2[j]+(lst2[j]-lst1[j])/(4**(j+1)-1)) | ||
delta = abs(lst2[-1]-lst1[-1]) | ||
lst1=lst2 | ||
mypprint(lst1) | ||
|
||
if __name__=='__main__': | ||
print("数值积分") | ||
a,b,h = 0.6,1.8,0.2 | ||
fs=[5.7,4.6,3.5,3.7,4.9,5.2,5.5] | ||
print("\n梯形公式") | ||
trapezoidal(a,b,h,fs) | ||
|
||
print("\n辛普森公式") | ||
simpson(a,b,h,fs) | ||
|
||
print('\n龙贝格公式') | ||
print("函数:{}, 区间:{} 精度:{}".format('sin(x^4)','[1,2]',1e-4)) | ||
romberg(1,2,lambda x:sin(x**4),1e-4) | ||
|
||
|
||
|
||
``` |
Binary file not shown.
77 changes: 77 additions & 0 deletions
77
数学类/计算方法/code/numerical_integration/numerical_integration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
######################################################################### | ||
# File : numerical integration.py | ||
# Author: mbinary | ||
# Mail: [email protected] | ||
# Blog: https://mbinary.xyz | ||
# Github: https://github.com/mbinary | ||
# Created Time: 2018-05-11 08:58 | ||
# Description: | ||
# numerical intergration: using Newton-Cotes integration, and Simpson | ||
# 数值积分, 使用 牛顿-科特斯积分, 辛普森 | ||
######################################################################### | ||
|
||
from math import sin | ||
|
||
import numpy as np | ||
|
||
def mypprint(lst): | ||
for i in lst: | ||
print(('%.4f'%i).ljust(10),end='') | ||
print() | ||
|
||
def trapezoidal(a,b,h,fs): | ||
'''梯形积分公式''' | ||
xs = [i for i in np.arange(a,b+h,h)] | ||
print('x'.ljust(10),end='') | ||
mypprint(xs) | ||
print('fx'.ljust(10),end='') | ||
mypprint(fs) | ||
ret = h*(sum(fs)-fs[0]/2 - fs[-1]/2) | ||
print(ret) | ||
return ret | ||
|
||
|
||
def simpson(a,b,h,fs): | ||
'''辛普森积分公式''' | ||
xs = [i for i in np.arange(a,b+h,h)] | ||
print('x'.ljust(10),end='') | ||
mypprint(xs) | ||
print('fx'.ljust(10),end='') | ||
mypprint(fs) | ||
ret = h/3*(4* sum(fs[1::2])+ 2*sum(fs[2:-1:2]) + fs[0]+fs[-1]) | ||
print(ret) | ||
return ret | ||
|
||
|
||
def romberg(a,b,f,epcilon): | ||
'''romberg(龙贝格) 数值积分''' | ||
h = b-a | ||
lst1=[h*(f(a)+f(b))/2] | ||
mypprint(lst1) | ||
delta = epcilon | ||
k=1 | ||
while delta >= epcilon: | ||
h/=2 | ||
k+=1 | ||
lst2=[] | ||
lst2.append((lst1[0]+h*2*sum(f(a+(2*i-1)*h) for i in range(1,2**(k-2)+1)))/2) | ||
for j in range(0,k-1): | ||
lst2.append(lst2[j]+(lst2[j]-lst1[j])/(4**(j+1)-1)) | ||
delta = abs(lst2[-1]-lst1[-1]) | ||
lst1=lst2 | ||
mypprint(lst1) | ||
|
||
if __name__=='__main__': | ||
print("数值积分") | ||
a,b,h = 0.6,1.8,0.2 | ||
fs=[5.7,4.6,3.5,3.7,4.9,5.2,5.5] | ||
print("\n梯形公式") | ||
trapezoidal(a,b,h,fs) | ||
|
||
print("\n辛普森公式") | ||
simpson(a,b,h,fs) | ||
|
||
print('\n龙贝格公式') | ||
print("函数:{}, 区间:{} 精度:{}".format('sin(x^4)','[1,2]',1e-4)) | ||
romberg(1,2,lambda x:sin(x**4),1e-4) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+299 KB
数学类/计算方法/code/numerical_integration/第2组-朱河勤-PB16030899 -numerical_integration.zip
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
**<span style="float:right">PB16030899-朱河勤 <br>2018-5-20<span>** | ||
|
||
|
||
# <center> 牛顿迭代解非线性方程组 | ||
>书上p186, 附录1程序10 | ||
# 程序源码 | ||
```python | ||
|
||
import sympy | ||
import numpy as np | ||
from math import sqrt | ||
|
||
def solveNonlinearEquations(funcs:[sympy.core],init_dic:dict,epsilon:float=0.001,maxtime:int=50)->dict: | ||
'''solve nonlinear equations:''' | ||
li = list(init_dic.keys()) | ||
delta = {i:0 for i in li} | ||
ct = 0 | ||
while 1: | ||
ct+=1 | ||
ys = np.array([f.subs(init_dic) for f in funcs],dtype = 'float') | ||
mat = np.matrix([[i.diff(x).subs(init_dic) for x in li] for i in funcs ],dtype = 'float') | ||
delt = np.linalg.solve(mat,-ys) | ||
for i,j in enumerate(delt): | ||
init_dic[li[i]] +=j | ||
delta[li[i]] = j | ||
print("第{}次迭代: {}".format(ct,init_dic)) | ||
if ct>maxtime: | ||
print("after iteration for {} times, I still havn't reach the accurrency.\ | ||
Maybe this function havsn't zeropoint\n".format(ct)) | ||
return init_dic | ||
if sqrt(sum(i**2 for i in delta.values()))<epsilon:return init_dic | ||
|
||
if __name__ == '__main__': | ||
x,y = sympy.symbols('x y') | ||
funcs=[x**2+y**2-1,x**3-y] | ||
init = {x:0.8,y:0.6} | ||
epsilon = 1e-5 | ||
print("迭代法求解非线性方程组") | ||
for i in funcs: | ||
print('| ',i, '= 0') | ||
print("初值: {}".format(init)) | ||
print("精度: {}".format(epsilon)) | ||
res = solveNonlinearEquations(funcs,init,epsilon) | ||
print("结果: {}".format(res)) | ||
|
||
``` | ||
# 算法描述 | ||
![](1.jpg) | ||
|
||
直到 delta x, delta y 的绝对值小于epsilon | ||
|
||
# 测试结果 | ||
![](test.png) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
######################################################################### | ||
# File : sol_nonLinear.py | ||
# Author: mbinary | ||
# Mail: [email protected] | ||
# Blog: https://mbinary.xyz | ||
# Github: https://github.com/mbinary | ||
# Created Time: 2018-05-20 09:31 | ||
# Description: | ||
######################################################################### | ||
|
||
import sympy | ||
import numpy as np | ||
from math import sqrt | ||
|
||
def solveNonlinearEquations(funcs:[sympy.core],init_dic:dict,epsilon:float=0.001,maxtime:int=50)->dict: | ||
'''solve nonlinear equations:''' | ||
li = list(init_dic.keys()) | ||
delta = {i:0 for i in li} | ||
ct = 0 | ||
while 1: | ||
ct+=1 | ||
ys = np.array([f.subs(init_dic) for f in funcs],dtype = 'float') | ||
mat = np.matrix([[i.diff(x).subs(init_dic) for x in li] for i in funcs ],dtype = 'float') | ||
delt = np.linalg.solve(mat,-ys) | ||
for i,j in enumerate(delt): | ||
init_dic[li[i]] +=j | ||
delta[li[i]] = j | ||
print("第{}次迭代: {}".format(ct,init_dic)) | ||
if ct>maxtime: | ||
print("after iteration for {} times, I still havn't reach the accurrency.\ | ||
Maybe this function havsn't zeropoint\n".format(ct)) | ||
return init_dic | ||
if sqrt(sum(i**2 for i in delta.values()))<epsilon:return init_dic | ||
|
||
if __name__ == '__main__': | ||
x,y = sympy.symbols('x y') | ||
funcs=[x**2+y**2-1,x**3-y] | ||
init = {x:0.8,y:0.6} | ||
epsilon = 1e-5 | ||
print("迭代法求解非线性方程组") | ||
for i in funcs: | ||
print('| ',i, '= 0') | ||
print("初值: {}".format(init)) | ||
print("精度: {}".format(epsilon)) | ||
res = solveNonlinearEquations(funcs,init,epsilon) | ||
print("结果: {}".format(res)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+289 KB
数学类/计算方法/code/solve_nonLinear_equation/第2组-朱河勤-PB16030899-zipsolve_nonLinear_equation.zip
Binary file not shown.
Oops, something went wrong.