Preview

CS 450 Homework 2 Question 1

Satisfactory Essays
Open Document
Open Document
518 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
CS 450 Homework 2 Question 1
import numpy as np import scipy as sp import matplotlib.pyplot as plt import scipy.linalg as la import scipy.io as sio
D = sio.loadmat("baseball_data.mat")
# X represents the total number of wins per team
X = D["X"].ravel()
# Y represents the total payroll per team
Y = D["Y"].ravel()
# The number of rows of matrix A m=X.size #by sorting the value of X, I realized that the minimum value in X is 672 and the maximum is 956, so I made the plotting range for x-axis from 650 to 1000

# n = 0
A=np.ones((m,1))
Q, R = la.qr(A) y=Q.transpose().dot(Y) x1=la.solve(R[0:1],y[0:1]) x_index= np.linspace(650, 1000, 256, endpoint=True) y_index=x1*np.ones((256,1)) plt.plot(X, Y,'o') plt.plot(x_index, y_index,label = 'fitted polynomial by QR factorization (n=0)') plt.xlabel('Wins') plt.ylabel('Payroll') plt.legend() plt.show()

# n = 1
A=np.ones((m,2))
A[:,1] = X
Q, R = la.qr(A) y=Q.transpose().dot(Y) x2=la.solve(R[0:2,0:2],y[0:2]) x_index= np.linspace(650, 1000, 256, endpoint=True) y_index=x2[0]+x2[1]*x_index plt.plot(X, Y,'o') plt.plot(x_index, y_index,label = 'fitted polynomial by QR factorization (n=1)') plt.xlabel('Wins') plt.ylabel('Payroll') plt.legend() plt.show()

# n =2
A = np.ones((m,3))
A[:,1] = X
A[:,2] = X**2
Q,R = la.qr(A) y=Q.transpose().dot(Y) x3 = la.solve(R[0:3,0:3],y[0:3]) x_index = np.linspace(650,1000,256,endpoint = True) y_index=x3[0]+x3[1]*x_index +x3[2]*((x_index)**2) plt.plot(X, Y,'o') plt.plot(x_index, y_index,label = 'fitted polynomial by QR factorization (n=2)') plt.xlabel('Wins') plt.ylabel('Payroll') plt.legend() plt.show()

# n = 3
A = np.ones((m,4))
A[:,1] = X
A[:,2] = X**2
A[:,3] = X**3
Q,R = la.qr(A)

y=Q.transpose().dot(Y)

x4 = la.solve(R[0:4,0:4],y[0:4])

x_index = np.linspace(650,1000,256,endpoint = True)

y_index=x4[0]+x4[1]*x_index +x4[2]*((x_index)**2)+ x4[3]*((x_index)**3)

plt.plot(X, Y,'o') plt.plot(x_index, y_index,label = 'fitted polynomial by QR

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Predicted VO2 = 30 +1 × (X), where X is the time in minutes to complete a 1.5-mile run and the SEE is 5 ml/kg/min.…

    • 258 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 8 Assignment 1

    • 1415 Words
    • 6 Pages

    This project used an Atmega644 microcontroller clocked at 20MHz in each of the two functional modules for processing. Memory storage is provided by a standard Secure Digital (SD) card. Xbee modules provide bidirectional wireless communication and we use the TLV5616 DAC chip for generating analog audio. The LM358 dual op amp provides active filtering to the output of the DAC. Music files can be added to the SD card using any computer with a multimedia card reader. Once the base station detects an SD card inserted into the holder, it awaits data requests from the portable module. The portable module requests data when required and feeds these values into the DAC. The DAC output is low-pass filtered by the op amp, which also buffers the DAC output before it reaches the audio output…

    • 1415 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    Nt1310 Unit 3 Maths

    • 552 Words
    • 3 Pages

    When addition or subtraction is performed, answers are rounded to the least significant decimal place.…

    • 552 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Assigned: Sep 2, 2011 Due: Sep 15, 2011 1:30 PM in class Lead TAs: Athula Balachandran Wolf Richter…

    • 733 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    A good example of refraction of light and reflection of light is a rainbow. Sunlight enters the rain droplet at a specific angle and the rain droplet separates the white light into many different colors. This angle is a fixed measurement between your eye and the sun. What color is refracted depends upon the critical angle, which is the angle the sunlight strikes the back of the rain droplet. Red light bends the least while violet light bends the most all the other colors bend at an angle that is between the two. Each rain droplet reflects all colors at a given point and time, but only one color comes back to your eye, requiring millions of rain droplets to create a rainbow. As the rain droplets fall…

    • 395 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3 Assignment 1

    • 1410 Words
    • 6 Pages

    Don’t limit yourself to modular sizes listed in a catalog - surf2 tables are available in 1 inch…

    • 1410 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    cout << "You are in factorial program of C++. Please enter a +ve integer:- ";…

    • 426 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    I recently had to deal with a problem with the Event Name as: BlueScreen. The Locale ID of the fault can be designated by the numerical value as: 5146. I am a touch apprehensive as to whether such a typical fault has been triggered owing to a virus attack. What should I do to eliminate the fault and ensure that the problem does not occur all over again?…

    • 474 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1310 Unit 3 Assignment 1

    • 3113 Words
    • 13 Pages

    Please verify that (1) all pages are present, (2) all figures are correct, (3) all fonts and special characters are correct, and (4) all text and figures fit within the red…

    • 3113 Words
    • 13 Pages
    Powerful Essays
  • Good Essays

    Mman2400-June 2007 Paper

    • 595 Words
    • 12 Pages

    The boom is supported by the winch cable that has a diameter of 6 mm and an allowable normal stress of O"allow 170 MPa. Determine the greatest load including the cage that can be supported without causing the cable to fail when 0 = 30°, and…

    • 595 Words
    • 12 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 3 Assignment 1

    • 2469 Words
    • 10 Pages

    “Tell me and I forget. Show me and I remember. Involve me and I understand.” Chinese proverb One’s understanding of network protocols can often be greatly deepened by “seeing protocols in action” and by “playing around with protocols” – observing the sequence of messages exchanged between two protocol entities, delving down into the details of protocol operation, and causing protocols to perform certain actions and then observing these actions and their consequences. This can be done in simulated scenarios or in a “real” network environment such as the Internet. The Java applets that…

    • 2469 Words
    • 10 Pages
    Good Essays
  • Satisfactory Essays

    NTFS is the newer filing system from Windows only Windows 2000 and higher use NTFS and FAT32. Which file system is intended primarily for use in large USB flash drives? I think it would be NTSF it a little more better an newer when it comes to the new OS out there like windows 8/7/ and maybe Vista XP just in case you have application that might run better on vista and XP. Plus since USB didn’t come out until Windows 98 well that when I first saw a USB port…

    • 462 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    When addressing system performance, a key element that is often overlooked is Disk Fragmentation. Even on a brand new system with plenty of RAM and processing speed, the performance of the hard disk may be a bottleneck causing issues. It takes time to load large data files into memory - issues become particularly noticeable when dealing with movies, video clips, database files or image files which may easily be several gigabytes in size. On a freshly formatted disk, these files load fairly quickly. Over time, however you may start to notice performance issues - caused by disk fragmentation.…

    • 356 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    COM 100 Exam 1

    • 1961 Words
    • 9 Pages

    You will have 60 minutes to complete the exam from the time it is distributed. You will have ample time to read each test item carefully and respond to each test item thoughtfully. Test items are not intended to be tricky, but rather to assess the depth of your understanding.…

    • 1961 Words
    • 9 Pages
    Powerful Essays
  • Better Essays

    1) You can call the module several times instead of writing it out each time.…

    • 1580 Words
    • 11 Pages
    Better Essays