# file: lecture_13/p03.py # # revision history: # # 20230928 (JP): initial version # # Solution to the third exam problem. # # To run this script, do this: # # python p03.py # #------------------------------------------------------------------------------ # import required system modules # import os import sys import math import numpy as np #------------------------------------------------------------------------------ # # Let's try the exam problem # #------------------------------------------------------------------------------ # (a) a simple constant matrix # T = np.array([[2, 3], [4, 5]]) x = np.array([[5],[10]]) print("x = [5,10]:\n", T @ x) scale = float(3) x_sc = scale * x print("x = [15,30]:\n", T @ x_sc) print("error = :\n", scale * (T @ x) - T @ (x_sc)) # (b) nonlinear # a = float(6.0) b = float(7.0) c = float(8.0) d = float(9.0) x = np.array([1,2]) y = np.array([a * x[0] * x[0] + b * x[1], c * x[0] + d * x[1] * x[1]]) print("x = \n", x) print("y = \n", y) scale = float(3) x_sc = scale * x y_sc = np.array([a * x_sc[0] * x_sc[0] + b * x_sc[1], c * x_sc[0] + d * x_sc[1] * x_sc[1]]) print("x_sc = \n", x_sc) print("y_sc = \n", y_sc) print("y_est = \n", y_sc / scale) # (c) nonlinear (a constant) # print("y1 = 1 * x2") print("y2 = b * y2 * x1 - or - x1 = 1/b") print("degenerate case = x1 is constant: y1 scales with x2") # # end of file