Menu

[r2807]: / trunk / course / examples / scipy / example10.2.5  Maximize  Restore  History

Download this file

18 lines (14 with data), 382 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
c1,c2= 5.0,2.0
i = r_[1:11]
xi = 0.1*i
yi = c1*exp(-xi)+c2*xi
zi = yi + 0.05*max(yi)*randn(len(yi))
A = c_[exp(-xi)[:,NewAxis],xi[:,NewAxis]]
c,resid,rank,sigma = linalg.lstsq(A,zi)
xi2 = r_[0.1:1.0:100j]
yi2 = c[0]*exp(-xi2) + c[1]*xi2
xplt.plot(xi,zi,'x',xi2,yi2)
xplt.limits(0,1.1,3.0,5.5)
xplt.xlabel('x_i')
xplt.title('Data fitting with linalg.lstsq')
xplt.eps('lstsq_fit')
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.