#Task 2 #Compare print ("Average difference between 21 and 22:", np.mean(np.abs((z-f(x,y))(z)) * 100, "X #Task 3

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Python Language

Item 2

[hint: use linspace and meshgrid to generate a gridded coordinates]

I want you to create random sampling (10 sets, 500 random points from -20 to 20)

  • first z1-value: use the 2D gaussian formula to get the z
  • second z2-value: use the interpolation using x&y random points as query points xi

Task1: then compare (% diff) between z1 and z2 for each set.

Task2: then compare (% diff) between z1 and z2 average of the 10 sets.

Task3: using the averaged value of z1-values, interpolate it onto a new grid with the size of 50x50 grid and plot the result.

Task4: plot individually all the random samplings for z1 and z2

------------------------------------------------

I did a code for this but it runs "error" , how do you fix this? 

[12] import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
#1
for i in range (10) :
x= np.random.uniform(-20, 20, 500)
y=np.random.uniform(-20, 20, 500)
#Gaussian Formula
z=np.exp(-0.5*(x**2 + y**2))
# Interpolation
f= interpolate.interp2d (x,y,z, kind='cubic')
#Compare
print("% difference between 21 and 22 for set
#Task 3
#Using the averaged value of 21-values
#Task 2
#Compare
print ("Average difference between 21 and 22:", np.mean(np.abs((z-f(x,y))/z)) * 100, "%
x_new = np.linspace(-20, 20,50)
y_new = np.linspace(-20, 20, 50)
i,
#Interpolate the data to the new grid
f_new = interpolate.interp2d(x,y,z, kind='cubic')
z_new=f_new(x_new, y_new)
#Plotting
plt.imshow(z_new, extent=(-20,20,-20, 20))
plt.show()
#Task 4
#Plotting random samplings in 21 and 22
for i in range (10):
(np.mean(np.abs((z - f(x,y)) / z)) * 100, "%")
Transcribed Image Text:[12] import numpy as np import matplotlib.pyplot as plt from scipy import interpolate #1 for i in range (10) : x= np.random.uniform(-20, 20, 500) y=np.random.uniform(-20, 20, 500) #Gaussian Formula z=np.exp(-0.5*(x**2 + y**2)) # Interpolation f= interpolate.interp2d (x,y,z, kind='cubic') #Compare print("% difference between 21 and 22 for set #Task 3 #Using the averaged value of 21-values #Task 2 #Compare print ("Average difference between 21 and 22:", np.mean(np.abs((z-f(x,y))/z)) * 100, "% x_new = np.linspace(-20, 20,50) y_new = np.linspace(-20, 20, 50) i, #Interpolate the data to the new grid f_new = interpolate.interp2d(x,y,z, kind='cubic') z_new=f_new(x_new, y_new) #Plotting plt.imshow(z_new, extent=(-20,20,-20, 20)) plt.show() #Task 4 #Plotting random samplings in 21 and 22 for i in range (10): (np.mean(np.abs((z - f(x,y)) / z)) * 100, "%")
[12]
#Compare
print("% difference between 21 and 22 for set
#Task 2
#Compare
print ("Average difference between 21 and 22:", np.mean(np.abs((z-f(x,y))/z)) * 100, "%"
#Task 3
#Using the averaged value of 21-values
x_new = np.linspace(-20, 20,50)
y_new = np.linspace(-20, 20, 50)
#Interpolate the data to the new grid
f_new = interpolate.interp2d(x,y,z, kind='cubic')
z_new= f_new(x_new, y_new)
#Plotting
plt.imshow(z_new, extent=(-20,20,-20, 20))
plt.show()
#Task 4
#Plotting random samplings in 21 and 22
for i in range (10) :
x = np.random.uniform(-20, 20, 500)
y = np.random.uniform(-20, 20, 500)
#using the 2D Gaussian formula to get the z
z= np.exp(-0.5*(x**2 + y**2))
#using the interpolation using x and y random pts
f = interpolate.interp2d(x, y, z, kind= 'cubic')
#plot 21
plt.imshow(z,extent=(-20, 20, -20, 20))
(np.mean(np.abs((z - f(x,y)) / z)) * 100, "%")
plt.show()
Transcribed Image Text:[12] #Compare print("% difference between 21 and 22 for set #Task 2 #Compare print ("Average difference between 21 and 22:", np.mean(np.abs((z-f(x,y))/z)) * 100, "%" #Task 3 #Using the averaged value of 21-values x_new = np.linspace(-20, 20,50) y_new = np.linspace(-20, 20, 50) #Interpolate the data to the new grid f_new = interpolate.interp2d(x,y,z, kind='cubic') z_new= f_new(x_new, y_new) #Plotting plt.imshow(z_new, extent=(-20,20,-20, 20)) plt.show() #Task 4 #Plotting random samplings in 21 and 22 for i in range (10) : x = np.random.uniform(-20, 20, 500) y = np.random.uniform(-20, 20, 500) #using the 2D Gaussian formula to get the z z= np.exp(-0.5*(x**2 + y**2)) #using the interpolation using x and y random pts f = interpolate.interp2d(x, y, z, kind= 'cubic') #plot 21 plt.imshow(z,extent=(-20, 20, -20, 20)) (np.mean(np.abs((z - f(x,y)) / z)) * 100, "%") plt.show()
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY