Professional Documents
Culture Documents
Objectives:
At the end of the exercise, the students should be able to:
Instruction:
Solve the following problems analytically (manual computation) and by creating a
code on Google Colab. You will be required to plot data points and the linear /
polynomial model equation. Each problem must have an analytical solution and the
code used in solving the given problem. You can put your solution and coding below the
“Analytical Solution:” and “Coding on Google Colab:” titles, respectively.
Note: You will be using Google Colab to perform matrix operation to find the
determinants, coefficients and the model equation, and plotting data along with the
model equation.
DCEE23 – Numerical Methods and Analysis
Problem 1:
A study was done to compare the speed x (in miles per hour) with the mileage y
(in miles per gallon) of an automobile. The results are shown in the table.
Fit a linear model and a quadratic model for the data. Determine which model
better fits the data. Plot the data along with the linear and quadratic model.
DCEE23 – Numerical Methods and Analysis
Analytical Solution:
DCEE23 – Numerical Methods and Analysis
DCEE23 – Numerical Methods and Analysis
x = np.array([15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75])
y = np.array([22.3, 25.5, 27.5, 29, 28.8, 30, 29.9, 30.2, 30.4, 28.8, 27.4, 25.3, 23.3])
det_A = np.linalg.det(A)
print("Coefficients:", coefficients)
plt.xlabel('Speed (x)')
plt.ylabel('Mileage (y)')
plt.legend()
plt.grid(True)
plt.show()
Problem 2:
A basketball is dropped from a height of about 5.25 feet. The height of the
basketball is recorded 23 times at intervals of about 0.02 second. The results are shown
in the table.
Fit a linear model and a quadratic model for the data. Determine which model
better fits the data. Plot the data along with the linear and quadratic model.
DCEE23 – Numerical Methods and Analysis
DCEE23 – Numerical Methods and Analysis
Analytical Solution:
DCEE23 – Numerical Methods and Analysis
DCEE23 – Numerical Methods and Analysis
import numpy as np
import matplotlib.pyplot as plt
# Given data
height = np.array([5.23594, 5.20353, 5.16031, 5.0991, 5.02707, 4.95146, 4.58062, 4.74979,
4.63096, 4.50132,
4.35728, 4.19523, 4.02958, 3.84593, 3.65507, 3.44981, 3.23375, 3.01048, 2.76921, 2.52074,
2.25786,
1.98058, 1.63488])
time = np.array([0, 0.02, 0.04, 0.06, 0.08, 0.099996, 0.119996, 0.139992, 0.159988, 0.179988,
0.199984,
0.219984, 0.23998, 0.25993, 0.27998, 0.299976, 0.319972, 0.339961, 0.359961, 0.379951,
0.399941,
0.419941, 0.439941])
# Linear model
linear_coeffs = np.polyfit(time, height, 1)
linear_model = np.polyval(linear_coeffs, time)
# Quadratic model
quadratic_coeffs = np.polyfit(time, height, 2)
quadratic_model = np.polyval(quadratic_coeffs, time)