,calculus ,a1 ,lab #7 ,9troduc;n4 ,? lab is ab curve fitt+ & l9e> regres.n4 ,x repres5ts a basic applic,n ( calculus 6/ati/ics & data model+4 ,a -mon pro#m 9 appli$ ma? is 6f9d a l9e or o!r curve pass+ "? a set ( data po9ts4 ,typic,y ! data po9ts -e f f exp]i;tal process2 s !y >rive 3ta9+ approxim,ns & ]rors4 ,!y don't exactly lie on ! l9e or smoo? curve "o is seek+4 ,! purpose ( ? lab is 6see h[ we c use :at we "k ab derivatives & optimiz,n 6f9d ! /rai l9e seg;ts f ea* (! #j data po9ts 6! l9e4 ,! sum (! l5g?s ( ^! seg;ts is a m1sure (! gd;s ( fit (! l9e4 ,we wd !n try 6m9imize ! sum ( ^! l5g?s1 : >e %[n 9 ,figure #2_4 ,"! >e #2 di6iculties ) ? *oice (a quant;y 6m9imize4 ,! f/ is %[n 9 ,pro#m #1 #1_4 ,-pute ! p]p5dicul> 4t.e f ! po9t (4, 5) 6! l9e y .k mx+b_4 ,i wd d ? 0rememb]+ t any l9e p]p5dicul> 6! l9e y .k mx+b has slope -?1_/m#_4 ,? wd let me write ! equ,n (! l9e "? (4, 5) p]p5dicul> to y .k mx+b_4 ,i cd !n f9d ": ^? two l9es met1 & -pute ! 4t.e 2t ! po9t ( 9t]sec;n &! po9t (4, 5)_4 ,wd y feel l -put+ ? 4t.e =a bun* ( po9ts1 summ+ ! results1 & !n m9imiz+ ! sum8 ,! o!r pro#m ) m9imiz+ ? expres.n is t (t5 ! quant;y on ! ;x-axis c 2 m1sur$ exactly or q a3urately1 &! ]ror 9 ! exp]i;t is 9 ! det]m9,n ( ;y_4 ,if ? is #a s1 !n x wd seem 6make m s5se 6use z a m1sure (! ]ror 9 ! l9e n ! sum (! p]p5dicul> 4t.es 6! l9e1 b ! sum (! l5g?s ( v]tical seg;ts dropp$ f ! po9ts 6! l9e1 z %[n 9 ,figure #3_4 #2_4 ,write ! sum (! l5g?s (! v]tical seg;ts jo9+ ! po9ts (1, 1), (2, 1), (3, 2), (4, 5), & (5, 6) 6! l9e y .k mx+b_4 ,yr answ] w obvi\sly dep5d on ;m & ;b_4 ,x %d 3ta9 a bun* ( absolute values4 ,! expres.n y got 9 ,pro#m #2 %d look a :ole lot m tracta# ?an ! "o f ,pro#m #1, b "!'s / a di6iculty4 ,! tr\# ) us+ calculus 6m9imize ! expres.n f ,pro#m #2 is t ! absolute value func;n doesn't alw h a derivative4 ,"! isn't a simple algebraic expres.n =! derivative ( \x\_4 ,"o has 6say t ! derivative is #1 if x .1 #0, t x is -#1 if x "k #0, & t x is undef9$ at x .k #0_4 ,un.s y re,y lov$ "w+ ) absolute values 9 s*ool1 x's "!=e #b agd idea 6avoid !m "h if we c4 ,s let's try a ?ird approa*1 less 9tuitive ?an ! o!r two4 ,let's use z \r m1sure =! gd;s ( fit (! l9e n ! sum (! absolute values (! v]tical 4t.es 2t ! po9ts &! l9e1 b ! sum (! squ>es (! v]tical 4t.es 2t ! po9ts &! l9e4 ,! squ>es1 l ! absolute values1 >e gu>ante$ 6be non-negative2 b unlike \x\, x^2 has a simple derivative4 ,we c "!=e use calculus 6m9imize ! sum (! squ>es (! 4t.es1 &! l9e we get %d 2 a pretty gd fit 6! data4 (,there >e "s fanci] ju/ific,ns = ? *oice (a func;n 6m9imize1 b ,i / ?9k t at bottom ! r1son =! *oice is t x results 9 a r1sona# fit & we c d ! ma?_4) ,? process ( f9d+ a l9e t m9imizes ! sum (! squ>es (! v]tical 4t.es 2t ! po9ts &! l9e is call$ l1/ squ>es l9e> regres.n4 #3_4 ,write ! sum ;,s (! squ>es (! l5g?s (! v]tical seg;ts jo9+ ! po9ts (1, 1), (2, 1), (3, 2), (4, 5), & (5, 6) 6! l9e y .k mx+b_4 ,don't bo!r 6simplify #c yr answ]1 : w dep5d on ;m & b, & : w 3ta9 a bun* ( squ>es4 ,! goal n[ is 6f9d values = ;m & ;b t make ! sum f ,pro#m #3 z small z possi#4 ,"! >e a v>iety ( ways 6d ?1 b "h's a naive "o t "ws4 ,?9k ( bo? ;m & ;b z v>ia#s1 & ?9k (! sum ;,s ( squ>es ( v]tical 4t.es z a func;n ( ;m & ;b_4 ,if "! >e values ( ;m & ;b t m9imize ,s, !n at ! m9imum1 we c reg>d ;b z a 3/ant & ;m z a v>ia#2 & we h 6be at a m9imum ( ;,s z a func;n ( ;m_4 ,alt]natively1 we c reg>d ;m z a 3/ant & ;b z a v>ia#2 & we h 6be at a m9imum ( ;,s z a func;n ( ;b_4 ,s =! be/-fit l9e1 we expect t ?d,s_/dm# .k ?d,s_/db# .k #0_4 #4_4 ,reg>d ;m z a 3/ant & ;b z a v>ia#1 set ?d,s_/db# .k #0, & solve = ;b_4 ,! equ,n y get = ;b 9 t]ms ( ;m has a simple geometric 9t]pret,n4 ,! c5t] ( mass (! po9ts we >e "w+ ) is ! po9t #d (3, 3) ^: ;x coord9ate is ! av]age (! ;x coord9ates (! #5 po9ts & ^: ;y coord9ate is ! av]age ( _! ;y coord9ates4 ,y %d 2 a# 69t]pret ! equ,n 9 ,pro#m #4 z say+ t ! l9e y .k mx+b m/ pass "? ! c5t] ( mass (! po9ts4 #5_4 ,n[ t y "k ! m9imum value = b, y c plug ? value 96yr =mula = ,s, -pute ?d,s_/dm#, & set x equal to #0 z well4 ,solve = ;m & ;b_4 ,plot ! l9e y .k mx+b tgr )! #5 data po9ts4 ,! l9e "\ 6look z if x fits ! po9ts at l1/ z well z any o!r /raiabola y .k ax^2"+bx+c _4 ,we mies (! l5g?s ( v]tical seg;ts jo9+ ! data po9ts 6! curve "w$ 2f1 :y n try ! same idea ag8 #6_4 ,write ! sum ;,s (! squ>es (! l5g?s (! v]tical seg;ts jo9+ ! po9ts (1, 1), (2, 1), (3, 2), (4, 5), & (5, 6) 6! p>abola y .k ax^2"+bx+c_4 ,don't bo!r 6simplify yr answ]1 : w dep5d on ;m & b, & : w 3ta9 a bun* ( squ>es4 ,! goal n[ is 6f9d values = a, b, & ;c t make ! sum f ,pro#m #6 z small z possi#4 ,proce$ j z 2f3 ?9k ( a, b, & ;c z v>ia#s1 &! sum ;,s z a func;n ( a, b, & ;c_4 ,=! be/-fit p>abola1 we expect ?d,s_/da# .k ?d,s_/db# .k ?d,s_/dc# .k #0_4 #f #7_4 ,-pute ?d,s_/da#, ?d,s_/db#, & ?d,s_/dc#_4 ,set !m all equal to #0, & solve = a, b, & ;c_4 ,i'd use ,maple 6solve !m tgr1 b x is al j a hi< s*ool algebra pro#m4 ,!n plot ! p>abola y .k ax^2"+bx+c tgr )! #5 data po9ts4 ,! p>abola "\ 6look z if x fits ! po9ts at l1/ z well z any o!r p>abola wd4 ,if x doesn't1 !n g back & look = yr mistake4 ,at ? po9t1 x %d seem hiabolas (curves ( degree #2)_4 ,"! >e re,y only two bits left 6f9i%+ up a -pletely g5]al !ory ( l9e> regres.n4 ,!ye >e a bit m not,n,y dem&+ ?an :at we've d"o s f>1 b if y /ay calm1 y %d 2 f9e4 ,y're / j "w+ ) l9e> equ,ns2 x's j t ! coe6ici5ts w 9volve slies (! v]tical 4t.es f ! ?ree data po9ts 6! l9e y .k mx+b is !n ,s .k (mx1+b-y1)^2"+(mx2+b-y2)^2"+(mx3 +b-y3)^2_4 #8_4 (a) ,reg>d ;m z a 3/ant1 & set ?d,s_/db# .k #0_4 ,%[ t at ! 5d ( all ! algebra1 y h ,'2g9.(equ,n.),' b .k "y<:]-m"x<:]_4 ,'5d.(equ,n.),' (;b) ,plug ? value = ;b 9to ;,s & y get ,s .k @(m(x1-"x<:])-(y1-"y<:])@)^2" +@(m(x2-"x<:])-(y2-"y<:])@)^2" +@(m(x3-"x<:])-(y3-"y<:])@)^2_4 ,n[ set ?d,s_/dm# .k #0 & solve = ;m_4 ,y %d get ,'2g9.(equ,n.),' #h m .k ?(x1-"x<:])(y1-"y<:])+(x2-"x<:])(y2 -"y<:])+(x3-"x<:])(y3-"y<:])_/(x1-"x<:] )^2"+(x2-"x<:])^2"+(x3-"x<:])^2"#_4 ,'5d.(equ,n.),' ,=mulas (1) & (2) = ;b & m, : g5]alize immly 6m ?an #3 data po9ts1 %[ t "o c get be/ fit l9es )\t do+ ! calculus anew = ea* set ( data4 ,y j -pute ! av]ages & plug 96! =mulas4 ,at ! 5d ( all ! calculus1 we "!=e h simple proc$ures = fitt+ l9es 6data1 : c easily 2 imple;t$ 9 a calculator or simple /ati/ics program4 #9_4 ,f9,y1 an op5-5d$ "q 6?9k ab4 ,c y design a way 6m1sure h[ close a set ( po9ts -es 6ly+ on a /rai