10.1的目的是已知矩陣a和向量b,使用最小二乘法求向量x,並求出殘差的模。
10.2的目的是求f(x) = (sin(x−2))^2 * e^(−x^(2))的最大值。
10.3的目的是計算n個點中每兩個點之間的距離。(使用scipy中的函式)
效果:
10.1**:a = [[3.29970122 4.7584198 0.11994548]
[1.10806457 4.11875492 7.82262271]
[4.11149242 2.98016391 1.85985557]
[0.10009004 7.7156862 6.02579851]
[0.55049201 3.73704831 7.01933204]]
b = [3.09298837 1.93370244 1.70862393 3.42058839 0.3262391 ]
x = [ 0.11220267 0.56255373 -0.15490991]
norm of residual = 0.3610278285377418
10.2
max func(0.216211) = 0.911685
iterations = 16, function evaluations = 32
10.3
[[0.68474557 6.35072199]
[0.57396044 6.34347976]
[2.44547344 4.21650739]
[5.85283499 1.59502687]]
[0.11102161 2.76677332 7.02323176 2.83312062 7.10030432 4.2991014 ]
import scipy
import scipy.linalg
import scipy.spatial
import scipy.optimize as opt
import math
defex10_1
(): print('10.1')
m = 5
n = 3
a = scipy.random.rand(m, n) * scipy.random.randint(1, 10)
b = scipy.random.rand(m) * scipy.random.randint(1, 10)
x, resid, rnk, s = scipy.linalg.lstsq(a, b)
print('a =', a)
print('b =', b)
print('x =', x)
print('norm of residual =', resid/n)
defex10_2
(): print('10.2')
func = lambda x: (math.sin(x - 2) ** 2) * math.exp(-x * x)
maximum = opt.fmin(lambda x: -func(x), 1, full_output=true, disp=0)
print('max func(%f) = %f'%(maximum[0], -maximum[1]))
print('iterations = %d, function evaluations = %d'%(maximum[2], maximum[3]))
defex10_3
(): print('10.3')
m = 2
n = 4
x = scipy.random.rand(n, m) * scipy.random.randint(1, 10)
print(x)
y = scipy.spatial.distance.pdist(x)
print(y)
ex10_1()
ex10_2()
ex10_3()
第十三周專案1(3)
檔名稱 作 者 胡昌星 完成日期 2016年5月25號 版 本 號 v6.0 問題描述 閱讀專案 虛析構函式 輸入描述 無 程式輸出 includeusing namespace std class cfraction 類與類的加 減 乘 除運算 cfraction operator cfracti...
第十三周專案1(3)
煙台大學計算機學院 檔名稱 xiangmu.cpp 完成日期 2017年11月26日 2 輸出用括號法表示的二叉排序樹 3 用遞迴演算法和非遞迴演算法查詢關鍵字55 4 分別刪除43和55,輸出刪除後用括號法表示的二叉排序樹。輸入描述 無 輸出描述 測試操作後的結果 include include ...
第十三周周小結
2.本週工作任務 幫助各個團隊明確第二次衝刺的目標,制定明天團隊的任務和分工,點評團隊倉庫。我負責的團隊安卓五組,web五組,web八組,web九組 3.作業情況 無 4.本週發現的問題 1 大部分團隊的任務制定的不夠具體,而且有些任務有點偏離了他們在第二次衝刺所指定的目標。2 在第一次團隊衝刺結束...