Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign 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)
Yearsx=[1960x1970x1990x2000]\renewcommand{\Bold}[1]{\mathbf{#1}}\verb|Years|\phantom{\verb!x!}\verb|=| \verb|[1960|\phantom{\verb!x!}\verb|1970|\phantom{\verb!x!}\verb|1990|\phantom{\verb!x!}\verb|2000]|
Populationx=[[3039585530]x[3707475887]x[5281653820]x[6079603571]]\renewcommand{\Bold}[1]{\mathbf{#1}}\verb|Population|\phantom{\verb!x!}\verb|=| \begin{array}{l} \verb|[[3039585530]|\\ \phantom{\verb!x!}\verb|[3707475887]|\\ \phantom{\verb!x!}\verb|[5281653820]|\\ \phantom{\verb!x!}\verb|[6079603571]]| \end{array}
LinearxEstimatexis:4494564853\renewcommand{\Bold}[1]{\mathbf{#1}}\verb|Linear|\phantom{\verb!x!}\verb|Estimate|\phantom{\verb!x!}\verb|is:| 4494564853
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)
QuadraticxEstimationxis:4472888287\renewcommand{\Bold}[1]{\mathbf{#1}}\verb|Quadratic|\phantom{\verb!x!}\verb|Estimation|\phantom{\verb!x!}\verb|is:| 4472888287
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) )
Degreex3xEstimationxis:4472888287\renewcommand{\Bold}[1]{\mathbf{#1}}\verb|Degree|\phantom{\verb!x!}\verb|3|\phantom{\verb!x!}\verb|Estimation|\phantom{\verb!x!}\verb|is:| 4472888287

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]])