Homework 1: Due Feb 7th Thursday before class.
Design a Java project that will use the following data:
int [] x= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int [] y= {-28,-12,-12,-1,-3,4,11,16,21,23,31,34,41,46,48,50,56,60,68,77,76};
a) Your code should be able to print the data as follows:
b) Your code should assume that the line passing through this data is y=ax+b (a,b will be given as input)
— Calculate all Y values according to your model(ax+b), put the values in array as yc[]
c) Another array e[] should be used to calculated the difference between yc[] and y[]. Print them.
d) Another array as e2[] will keep the squares of e[] array elements.
e) Print the total errors as the sum of all the elements of array e2[] : sumE
Let us call all the above steps as first run with sumE, try 10 runs with different values of a,b and store your sumE values. Find the best a,b that will give the smallest sumE.
Finally use a=5, b=-20 give your sumE.
Recent Comments