Question: Here is my code for the assignment below. Not able to get it to run. Can not use Scipy. Duck.txt is attahched. import numpy as

Here is my code for the assignment below. Not able to get it to run. Can not use Scipy. Duck.txt is attahched. Here is my code for the assignment below. Not able to get

import numpy as np from numpy import interp from numpy import polyfit from numpy import poly1d import matplotlib.pyplot as plt

import warnings warnings.simplefilter('ignore', np.RankWarning)

import numpy as np x0 = np.array(0.1) x = np.linspace(0, 1) y = np.linspace(0, 1)

def main(): x = [] y = []

with open('duck.txt') as f: for line in f: line = line.strip().split() x.append(float(line[0])) y.append(float(line[1]))

x = np.array(x) y = np.array(y)

f = np.interp(x0, x, y)

y1 = polyfit(x, y, 5) y11 = poly1d(y1) y2 = polyfit(x, y, 10) y22 = poly1d(y2) y3 = polyfit(x, y, 15) y33 = poly1d(y3) y4 = polyfit(x, y, 20) y44 = poly1d(y4) ''' c = np.interp(x, y, kind = 'cubic') ''' fig = plt.figure() plt.plot(x, y, 'o', label = 'Data') plt.plot(x, y11(x), 'r', label = ' Least Squares m = 5') plt.plot(x, y22(x), 'g', label = 'Least Squares m = 10') plt.plot(x, y33(x), 'b', label = 'Least Squares m = 15') plt.plot(x, y44(x), 'm', label = 'Least Sqaures m = 20') plt.suptitle("Least Squares Approx of Duck's Back") plt.axis([0, 14, -6, 4]) plt.legend(loc = 'lower left') plt.show()

figg = plt.figure() plt.plot(x, y44(x), 'r', label = 'Least Sqaures m = 20') plt.plot(x, f(x), 'b', label = 'Lagrange') plt.suptitle('Lagrange vs. Least Squares Approx') plt.axis([0, 14, -6, 4]) plt.legend(loc = 'lower left') plt.show()

figgg = plt.figure() plt.plot(x, y44(x), 'r', label = 'Least Sqaures m = 20') plt.plot(x, f(x), 'b', label = 'Lagrange') plt.plot(x, c(x), 'k', label = 'Cubic Splines') plt.suptitle('Cubic Spline Approx') plt.axis([0, 14, -6, 4]) plt.legend(loc = 'lower left') plt.show()

input()

if __name__ == '__main__': main()

it to run. Can not use Scipy. Duck.txt is attahched. import numpy

358167410123294976542 111222222222211000000 5360603 93916094700002 358167410123294976542 111222222222211000000 5360603 93916094700002

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!