from __future__ import print_function import numpy as np import hw2 def test_prob1(): print('Testing Problem 1') answer = hw2.prob1() passed = True for i in 1,2,3,4,5,6: if answer[i] is None: passed = False return passed n = 200 x = np.linspace(-20,20,n) y = np.array([ 33.16451376, 32.2400534 , 31.50695018, 30.15918837, 29.56937675, 28.25027706, 26.64582867, 27.17794046, 26.19563919, 25.83637811, 23.78938234, 22.65041138, 21.80453982, 20.435641 , 21.6201122 , 19.65849961, 19.1761254 , 19.51194805, 20.41184168, 19.30750068, 18.23738884, 18.2951348 , 19.08520874, 18.38654978, 17.79550117, 17.97717133, 18.42182327, 18.99311528, 16.38827558, 16.40481133, 15.79761073, 14.11764051, 14.55288863, 13.81597049, 14.60655325, 12.9799756 , 11.16724611, 11.98052671, 10.51083679, 8.79544057, 8.89080039, 8.23982796, 7.44553611, 7.55474819, 5.51485587, 6.53776506, 7.15376154, 6.84147849, 6.89583597, 6.84707639, 7.10579377, 5.32811923, 6.78111341, 4.98150869, 5.95916039, 5.12522722, 7.25638177, 7.47416854, 6.37009997, 7.6597893 , 5.79029938, 6.1461468 , 5.85914147, 4.65498951, 5.29691359, 5.88936067, 3.31864594, 4.14478246, 2.87550967, 3.69498422, 2.28667647, 1.94693258, 1.49666079, 0.85292245, -0.59723844, 1.13171315, -0.94301457, 0.12518301, 0.41126576, -0.50472557, 0.3538332 , 1.30074592, 0.74602607, 0.45586114, -0.62721144, 1.07524599, 1.6744171 , 2.03596932, 1.99840184, 3.15986675, 2.66225291, 3.09374385, 3.68499585, 2.58303365, 2.87925427, 4.44839834, 3.34679735, 1.58568071, 2.16335402, 2.32784327, 2.50993267, 1.4799193 , 0.76342795, 0.42661128, 1.2490075 , 0.94287743, 0.36321142, 0.67387483, 0.67893148, 1.72369995, 1.0582074 , 2.27857764, 2.99423034, 3.2505679 , 2.87719554, 4.97831487, 4.14747743, 5.50087065, 5.23541544, 5.06911997, 6.93040138, 7.40120033, 7.5123835 , 8.06026377, 7.64631658, 7.75161084, 8.25688147, 9.7642228 , 9.00762899, 8.0510806 , 8.76580829, 7.99588427, 7.97812092, 8.89349043, 7.9585635 , 7.24085978, 7.93110813, 8.85241259, 9.18410785, 10.3499514 , 9.4484789 , 11.01037193, 11.41925739, 11.70523631, 13.13814443, 13.68349667, 13.5498233 , 15.73169169, 14.95354942, 16.66049038, 17.40123896, 18.43552425, 18.31700867, 19.42688191, 19.91438148, 21.20507303, 20.37798744, 21.35166832, 21.42780688, 20.9655457 , 23.97598231, 22.25956779, 21.46803259, 23.70153495, 22.19540662, 23.4706575 , 24.13139648, 23.45152757, 24.0528219 , 24.5030733 , 25.39931457, 25.04554183, 26.08849446, 27.70288987, 29.44483949, 30.1339369 , 31.92231755, 32.24976088, 32.47586342, 33.8198723 , 33.54443888, 35.32664093, 36.2793697 , 38.12767961, 39.27814923, 39.25478724, 39.99056085, 40.00858487, 41.62672049, 42.45716727, 43.11374223, 42.73391889, 45.12852417, 45.01664258, 44.56058447, 44.72403943, 45.36705724, 46.2439076 , 46.72988681, 47.75501605]) def test_prob2(): print('Testing Problem 2') w_true = np.array([ 1.77472512, 0.43927399, 0.0962285 , -1.82400913]) w = hw2.prob2(x,y) return np.linalg.norm(w-w_true,np.inf) <= 1e-2 def test_prob3(): print('Testing Problem 3') w_true = np.array([ 1.53535947, 0.45845946, 0.09707821, -1.97939177]) w = hw2.prob3(x,y) return np.linalg.norm(w-w_true,np.inf) <= 1e-2 points = 0 total = 3 for f in test_prob1, test_prob2, test_prob3: if f(): print("Passed!") points += 1 else: print("Fail!") print("Got {} out of {} points!".format(points, total))