Project 3 Two-densonal arras Ma 9, 6 Thrd Prograng Project Two-Densonal Arras Larr Caretto Coputer Scence 6 Coputng n Engneerng and Scence Ma 9, 6 Outlne Quz three on Thursda for full lab perod See saple quz on hoe page of course web ste Project three Multlnear regresson Equatons to be solved Data structures to be used Lbrar progra use n separate code fle Fles You Can Download Eercse 8 Lnear Regresson Project nstructons on hoe page and projects page Other fles on projects page onl Data fle for project Lbrar progra for solvng sultaneous lnear equatons Ecel fle wth answers Ths lecture on hoe page and laborator presentatons page Ft lnear relatonshp to easured data pars (, ) a + b Have equatons to deterne a and b Get goodness-offt easures ŷ Ftted Lne ndcates data ponts Ftted value at s ŷ a + b 3 4 Project Three Regresson Have a result that depends on ore than one varable Eaple s essons fro desel engne that depends on fuel propertes essons b + b (cetane) + b (aroatcs) + b 3 (denst) Use easured data on essons, cetane, aroatcs to fnd b, b, b, b 3 General Regresson Use notaton so that we can wrte code for an nuber of predctve varables Call predctve varables,, 3, etc. Call response varable In prevous eaple, cetane, aroatcs, 3 denst, and essons For three varables the equaton s b + b + b + b 3 3 5 6
Project 3 Two-densonal arras Ma 9, 6 General Equaton and Data Data Set wth 3 and 8 In general we can have predctve varables, to k General odel equaton: b b + j j How do we represent the data? j Each data set conssts of one value of and one value for each of the j varables For data set, we can call the value of,, and we can call the value of j for data set j 7 3.55 3. 44 5.95 3.47 35 4.89 3.4 44 54 3.4 3.46 35 37 4.3 3.59 45 48 5.74.75 3 6.87 3.3 3 47 7.83 3.8 9 4 Each data set,, has a value for and each j 35 What are 4, 3, 3? 8 Suar of Data We use dfferent varables ( to ) to predct the value of another varable, We have sets of data nubered fro to - each data set has one value of, called, and one value of each j, called j all and values fro fle nput all data used to deterne b to b How do we fnd b j? Defne for all,..., - ote that there s no n odel Settng used to splf equatons Values of b,..., b found b solvng set of + sultaneous lnear equatons A b + A b + A b +...+ A b c Copute A j and c fro nput data Use lbrar progra to solve equatons 9 Equatons to be Used Copute the A j coeffcents Aj Copute the c coeffcents Use the lbrar routne provded to solve for b j c j j Aj bj c,, Coputng one A[][j] (A[][]) 3.55 3. 44 5.95 3.47 35 4.89 3.4 44 54 3.4 3.46 35 37 4.3 3.59 45 48 5.74.75 3 6.87 3.3 3 47 7.83 3.8 9 4 Aj j A + + 3 3 + 4 4 + 5 5 + 6 6 + 6 6 + 7 7 A
Project 3 Two-densonal arras Ma 9, 6 Coputng A[][] A[][] Coputng A[][] A[][] 3.55 3. 44 5.95 3.47 35 4.89 3.4 44 54 3.4 3.46 35 37 4.3 3.59 45 48 5.74.75 3 6.87 3.3 3 47 7.83 3.8 9 4 A A A (3.)(44) + (3.47)(35) + (3.4)(44) + (3.46)(35) + (3.59)(45) + 3.55 3. 44 5.95 3.47 35 4.89 3.4 44 54 3.4 3.46 35 37 4.3 3.59 45 48 5.74.75 3 6.87 3.3 3 47 7.83 3.8 9 4 A A (3.)(44) + (3.47)(35) + (3.4)(44) + (3.46)(35) + (3.59)(45) + (.75)() + (3.3)(3) + (3.8)(9) 3 4 Coputng one c[] c[] More Equatons to be Used 3.55 3. 44 5.95 3.47 35 4.89 3.4 44 54 3.4 3.46 35 37 4.3 3.59 45 48 5.74.75 3 6.87 3.3 3 47 7.83 3.8 9 4 c c + + 3 3 + 4 4 + 5 5 + 6 6 + 6 6 + 7 7 (3.)(.55) + 5 Copute estated values ˆ Copute the R value R b + ( j b j ˆ ) j ( ) 6 Requred Code Steps Input data on,,, and j Set each Copute A j and c (as A[][j] and c[]) Use lbrar progra that takes A j and c as nputs and returns soluton for b j Use b j to copute predcted values: ŷ Copute R and output results Gettng the Input Data Download data fle fro course web ste Data on fle start wth value of followed b sets of data Each data set starts wth followed b,, 3, etc. Can odf eercse eght nput functon Deterne b end of fle condton Reeber to set 7 8 3
Project 3 Two-densonal arras Ma 9, 6 Arras for Coputng A j and c Aj j c A j s D arra wth both densons at least the nuber of varables plus two c s D arra wth sae denson as A j s D arra wth dfferent densons Frst s the nuber of varables plus one Second s au data ponts s D arra; denson s au data ponts Code for Coputng A[][j] Aj j Use tpcal code for coputng a su A[][j] + [][] * [j][] What s the for loop for ths su? for ( ; < ; ++ ) How do we copute all the A[][j]? We need to place the coputaton of one A[][j] nsde two for loops over and j 9 Lbrar Functon to Get b j j a j j b,, Code varables use tpcal notaton for sste of lnear equatons shown above a j are left-hand sde coeffcents b are rght-hand-sde coeffcents j are unknowns There are equatons to be solved Lbrar Functon Defnton Functon prototpe (second denson requred for passng D arras to functons) bool GaussanEl( double a[][max_var], double b[], double [], nt _eqn ); a[][max_var] s left-hand sde arra (a j ) b[] s rght hand sde arra (b ) [] s unknown arra ( j ) _eqn s the nuber of equatons () Usng bool GaussanEl Functon returns an error flag n the functon nae True ndcates an error False ndcates a vald soluton f ( GaussanEl( A, c, b, + ) ) { cout << o soluton for b[j] ; return EXIT_FAILURE; } // reander of code 3 Copare prototpe and call Prototpe bool GaussanEl( double a[][max_var], double b[], double [], nt _eqn ); Rght-sde uber of Left-sde Unknowns equatons f ( GaussanEl( A, c, b, + ) ) { cout << o soluton for b[j] ; return EXIT_FAILURE; } 4 4
Project 3 Two-densonal arras Ma 9, 6 Passng the Second Denson Project Three Code Suar Use two fles: our code and the lbrar progra Place prototpe for lbrar progra n our code Make sure that the second denson for a[][j] (or A[][j]) s the sae for three cases The header n the lbrar progra The prototpe n our code Your declaraton of the A[][j] arra Input data on,,, and j Set each Copute A j and c Use lbrar progra that takes A j and c as nputs and returns soluton for b j Use b j to copute predcted values: ŷ Copute R and output results 5 6 5