Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***rewrite the following code in a different way using python*** import numpy as np import matplotlib.pyplot as plt x = np.arange(-10,10,.2) y = np.array([17.04550664, 16.8692958

***rewrite the following code in a different way using python***

import numpy as np import matplotlib.pyplot as plt x = np.arange(-10,10,.2) y = np.array([17.04550664, 16.8692958 , 16.97776091, 17.10458855, 16.0539128,16.65810917, 16.97396422, 16.76525952, 16.47198979, 16.62896536,16.38279055, 16.33779643, 16.43524622, 15.9605478 , 15.95500468,16.14474514, 16.01227655, 16.23575385, 15.94977848, 15.8078146,16.34270618, 15.9641272 , 15.98289508, 15.64494371, 15.78191372,15.87426077, 15.58354874, 15.85093963, 15.61810245, 15.64269543,15.54386695, 15.99820443, 15.58895264, 15.34437237, 15.6850416,15.241334 , 15.49259412, 15.02455113, 15.11685334, 15.38820646,15.46320607, 15.31679651, 15.2673155, 15.1573038 , 14.88980524,15.00984445, 15.03030457, 15.30278805, 15.12932768, 14.67754247,15.06481679, 14.89313305, 14.80521162, 15.03367186, 15.08856822,15.0399443 , 14.6574501 , 14.73533898, 14.83560173, 14.93690258,14.61867741, 14.65037061, 14.43949432, 14.39504497, 14.77057987,14.85337193, 14.54202934, 14.73170103, 14.57813784, 14.35185345,14.52847138, 14.73936005, 14.40039119, 14.69652954, 13.83593456,14.50078285, 14.33056417, 1423033701, 14.28570338, 13.84727692,14.17852028, 14.27176338, 14.47402592, 14.05311716, 13.97361225,14.01371286, 14.2761094 , 14.13795321, 13.94563219, 14.13382411,14.03037565, 14.18467975, 13.83072984, 13.88599485, 13.85368763,13.62018147, 13.95307499, 13.92721786, 13.85737287, 13.79096176]) y[77] = 14.230337010 #plt.plot(x,y)

# Polynomial fit of order 1 , 2 and 3 poly = [1,2,3]

res_dic = {}

for i in poly: _coeff = np.polyfit(x, y, i) _function = np.poly1d(_coeff) _pred = _function(x) res_dic.update({i:_pred})

# Exponential Fit _exp_fit = np.polyfit(x, np.log(y), 1) _exp_pred =_exp_fit[0]* np.exp(_exp_fit[1]*x) res_dic. update({4 : _exp_pred})

plt.plot(x, y, label = 'Original') plt.plot(x, res_dic[1], '.', label = '1st Degree fit') plt.plot(x, res_dic[2], 'o', label = '2nd Degree fit') plt.plot(x, res_dic[3], '+', label = '3rd Degree fit') plt.title('All Polynomial Fit') plt.legend(loc='best') plt.show()

plt.plot(x,y ,'_', label = 'original') plt.plot(x,res_dic[4],'*' , label = 'exp fit') plt.legend(loc='best')

plt.show()

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

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Is the person willing to deal with the consequences?

Answered: 1 week ago

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago