Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168695
Image: ubuntu2004
import numpy #import to use numpy package from numpy import * #import everything in numpy #input data : # [Time (t)][3 ,5 ,7 ,8 ,9 ] (sec) # [Signal Strength (m)][400 ,500 ,550 ,600 ,730] (millivolts) #approximate with : m=f(t)=c+b*sin(t)+a*tan(t) A0 = numpy.ones((1,5)) #create matrix (1x5) of scalar 1 A3 = numpy.matrix([3,5,7,8,9],dtype=float) #create data matrix t(1x5) A1=sin(A3) #matrix sin(t)(1x5) A2=tan(A3) #matrix tan(t) (1x5) A=concatenate((A0,A1,A2)) #combine A0, A1, A2 into A Y = matrix([400,500,550,600,730],dtype=float) #create data matrix Y(1x5) Y=Y.T #transpose of Y X=linalg.inv(A*A.T)*A*Y #calculate suitable set of [c,b,a] print "Coefficients = " print X plot(X[0,0]+X[1,0]*sin(x)+X[2,0]*tan(x), (x,0,10)) + list_plot(zip(A3.T,Y)) #plot the approximate curve and data points