Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Numerical Methods Homework

Views: 706
Kernel: SageMath 8.2
import numpy as np A = np.array([1960,1970,1990,2000]) show('Years = ', A) b = np.array([[3039585530],[3707475887],[5281653820],[6079603571]]) show('Population = ', b) linear = ((b[2]+b[1])/2)[0] show ('Linear Estimate is: ', linear)
c1, c2, c3 = np.polyfit(A,b, 2) show("Quadratic Estimation is: ",int(c3+c2*1980+c1*1980^2) ) linear/ (c3+c2*1980+c1*1980^2)
array([ 1.00484621])
c1, c2, c3, c4 = np.polyfit(A,b, 3) show("Degree 3 Estimation is: ", int(c4+c3*1980+c2*1980^2+c1*1980^3) )

The Quadratic and 3-rd degree Polynomial estimations were equally as accurate and fit more closely to the measured value of 4.4e9

def interpret(x, y, degree): return np.polyfit(x,y,degree) interpret(A,b,3)
array([[ -9.02815208e+03], [ 5.38439890e+07], [ -1.06960683e+11], [ 7.07767052e+13]])