Syeda Faryal A. answered 07/10/24
I'm here my beloved student
import numpy as np
# Define the function y = (2 * (X1^2)) + (X2^2)
def compute_y(X1, X2):
return 2 * (X1**2) + (X2**2)
# Generate all combinations of X1 and X2 values from -12 to 12
X1_values = np.arange(-12, 13)
X2_values = np.arange(-12, 13)
# Compute y for all combinations of X1 and X2
y_values = np.array([[compute_y(x1, x2) for x1 in X1_values] for x2 in X2_values])
# Flatten y_values into a 1D array
y_flat = y_values.flatten()
# Define bins for y
bins = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450]
# Initialize counts for each bin
bin_counts = [0] * (len(bins) - 1)
# Count how many values fall into each bin
for value in y_flat:
for i in range(len(bins) - 1):
if bins[i] <= value < bins[i + 1]:
bin_counts[i] += 1
break
# Print the counts for each bin
for i in range(len(bins) - 1):
print(f"Values in bin [{bins[i]}, {bins[i + 1]}): {bin_counts[i]}")
Timothy S.
11/07/13