Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribed

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

image text in transcribed

358167410123294976542 111222222222211000000 5360603 93916094700002 358167410123294976542 111222222222211000000 5360603 93916094700002

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

suggest a range of work sample exercises and design them

Answered: 1 week ago

Question

=+associated with political parties and if so, which ones? Are

Answered: 1 week ago