Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Midterminforma-on
• Whatdoesitcover?• WhatshouldIexpect?See:MidtermInforma-onpageonthewiki
What’sdueandwhen?• OSH4:
• Pleasenotethatthedeadlineis8:59pm,Fri,Oct20Donotcountonbeingabletosubmitlater,ortosenditbyemailaMerthedeadline.
LeastsquaresdatafiRng;ChainRule
Leastsquares(Linearregression)datafiRngcont’d..
UBCMath102
Fromlast-me.
• Wearegivensomedataandwanttodescribeitstrend.
• Howdowefitthebestlinethroughthedata?
• Thisisaprac-alapplica-onofcalculus,becauseitinvolvesminimiza-on.
• “LeastsquaresfiRng”–auseful(andmathema-callysimple)procedure
UBCMath102
Learninggoals
• UnderstandwhatdatafiRngmeansinthesimplest(linearleastsquares)seRng.
• Understandtheconnec-ontoop-miza-on• Beabletofitaliney=ax+bdatapoints• Instruc-onsforhowtouseaspreadsheettofitalinetodata
Last-me:Example
• Rainfalloverthreedays
• Findafor“bestline”
UBCMath102
Day 1 2 3
Rain(cm) 2 3.3 4
Whatis“best”line?
• Choselineforwhichtheresidualsareassmallaspossible!(minimize!)
UBCMath102
y=ax
(x1,y1)(xn,yn)
(xi,yi)
Whatisaresidual?
Residual=datavalue-theore-calvalue=yi–axi
UBCMath102
y=ax
(x1,y1)(xn,yn)
(xi,yi)
“Sumofsquareresiduals”
• SSR=(y1-ax1)2+(y2-ax2)2+...+(yn-axn)2• Short-handnota-on: SSR(a)=MinimizingSSR(a)isequivalenttofindingtheslopeofthelineforwhichthedevia-onsofdatafromthelinearesmallestoverall.
UBCMath102
Liney=ax;bestfitvalueofa:
• WeshowedthatthiswasobtainedbyminimizingSSR
• Theop-malvalueoftheslopeofthelinetofitthedata!
Defini-ons
• Amodelisafunc-onusedtorepresentorfitdata.Forexample,somecommonones:f(x)=ax,f(x)=ax+b,f(x)=Ce-kx.
• Residualsareameasureofhowfareachmodelvalueisfromthedatavalue:ri=yi-f(xi).
• TheSumofSquaredResiduals(SSR)isameasureofhowwellthemodelfitsallthedata:SSR=∑(yi-f(xi))2.
• SmallerSSRisbeher.UBCMath102
“Bestfit”
• Thebestfitmodelisthemodelwithparametervalue(s)(a,aandb,etc)thatgivesthesmallestSSR.
UBCMath102
(1)Bestfitlinewithintercepty=ax+b
• Theresidualsare(A)axi+b(B)(axi+b)2(C)yi-(axi+b)(D)yi2-(axi+b)2(E)yi-axi
Residualsforliney=ax+b
• ri=yi-(axi+b)
(x1,y1)
(xn,yn)
(xi,yi)
y=ax+b
(2)Forbestfitlinewithintercepty=ax+b
• Theresidualsareyi-(axi+b)andwewillminimize
(A)Σyi-(axi+b)(B)Σ|yi-(axi+b)|(C)Σ(yi-(axi+b))2(D)Σyi2-(axi+b)2(E)Noneoftheabove
(3)Forbestfitlinewithintercepty=ax+b
• WewillminimizeSSR=Σ(yi-(axi+b))2Withrespectto
(A)a(B)b(C)xi(D)xiandyi(E)bothaandb
(4)Howwouldwedothat?
Findvalueofaandbsuchthat
(A) d(SSR)/da=0(B) d(SSR)/db=0(C) Both(A)and(B)(D) noneoftheabove(E) Noclue
UBCMath102
Challenge!
• Forfun:Calculatevaluesofofaandbsuchthat
d(SSR)/da=0ANDd(SSR)/db=0WhereSSR=Σ(yi-(axi+b))2
UBCMath102
Bestfitlinewithintercepty=ax+b
• RESULT:(SeeSupplementonwiki,noneedtomemorizethese!)
• Where:
UBCMath102
Bestfitlinewithintercepty=ax+b
• Manyspreadsheets(excel,Google-sheets)willcomputesuchlinesforyouautoma-cally
• Someslidesfollowwithinstruc-ons.Orsee:M102Wiki
UBCMath102
Assignment7:Problem14
Usingaspreadsheettofitatrend-linetodata:yisthetotalvolumeofallchloroplastsinsideagivencellwithvolumexWanted:givendata,fittoit
Manyspreadsheetswillfitdata
Excel:HighlighttherowscontainingxanyvaluesInsert;chart;scaherplot
UBCMath102
Excelhasautoma-c“fitline”func-on
UBCMath102
y=0.5887x+0.0282R²=0.99493
0
0.5
1
1.5
2
2.5
3
3.5
4
0 1 2 3 4 5 6 7
AxisTitle
AxisTitle
y
y
Linear(y)
Or,useGooglesheets
UBCMath102
Hereweshowhowtocalculatebestfitsfromscratch
• CopythedatafromtheWebworkques-on
PasteintoGooglesheets(donotretype!)
Picksomevalueofaandcomputetheresiduals
UBCMath102
Residuals
UBCMath102
Squareresiduals
UBCMath102
SumofSquareResiduals(SSR)
UBCMath102
Computeslopeforbestfitliney=ax
UBCMath102
• xiyi• xi2• Σxiyi• Σxi2
•
• (Thisisbestslope)
UBCMath102
Computeslopeforbestfitliney=ax
TheSSRshouldbesmallforthebestfitline
• LargeSSRforarbitraryvalueofa:
• MuchsmallerSSRwhenweplugintheavaluewefound.
UBCMath102
Plotthedata
• MakeascaherplotofthedataandgetGooglesheetstofitabestlinetoit.
y=ax+b• Note:wecanalsodothisourselvesbycalcula-ngthequan--esaandbfromthedata
UBCMath102
Makeascaherplot
• Highlightthecellswithdata,includinglabels
• Insertchart:
UBCMath102
Formatchart
• Start
• Switchrowsandcolumns• UsecolumnAasheaders
UBCMath102
• Charts
• Scaher• (Selecttopchoice)
• Insert
Dataplotwillappear
UBCMath102
Addtrendline• {Controlclick}onchart
• Advancededit
• Customize• Scrolldownmenu• SelectTrendline;linear
UBCMath102
Trendlinewillappear
UBCMath102
Clickingonlinedisplaystrendline
UBCMath102
Lineagreeswithourowncalcula-ons
• Calculatedvalues
Calcula-ons
• Cells:
UBCMath102
ChainRule-Intro
UBCMath102
Func-oncomposi-on
• Afunc-ony=g(f(x))
UBCMath102
Whatisthecorrectdecomposi-on?
• Ifthefunc-onisThenthedecomposi-onis
Herearevaluesoff(x)atafewpoints
Thenf(f(3))isequalto:A. 3B. -3C. 0D. -2E. 2
(1)Func-oncomposi-on
UBCMath102
(2)Func-oncomposi-on
UBCMath102
ChainRuleofdifferen-a-on
• Ify=g(u)andu=f(x)arebothdifferen-ablefunc-onsandy=g(f(x))isthecompositefunc-on,thenthechainruleofdifferen-a-onstatesthat
UBCMath102
CoffeeBudget
• Rateofincreaseofmoneyspentoncoffee =
Rateofincreaseofpricepercup-mesRateofincreaseofcupsIdrink
(3)ChainRuleexample
UBCMath102
Solu-on
• Thefunc-onis.Let
UBCMath102
(4)Chainruleexample
Computethederiva-veof)
UBCMath102
(4)ChainruleexampleThederiva-veofis
(A)(B)(C)(D)(E)Noneoftheabove
UBCMath102
Chainruleexample(2)
Thederiva-veofis:Quo-entrule:
Chainruleappliedtoop-miza-on
UBCMath102
Anttrails
Iloveants!(butnotinmykitchen)
UBCMath102
Anttrails
Ants:trailforminginanarena• hhps://www.youtube.com/watch?v=-lz97WTM7aU
Ants:pheromonemarkings• hhps://www.youtube.com/watch?v=tAe3PQdSqzg
Anttrails
• Antscanfindtheshortestroutethatconnectstheirnesttoafoodsource.
• eachantsecretesachemicalpheromonethatotherantswillfollow.
UBCMath102
Findtheminimumtraillengthconnec-ngnesttotwofoodsources
UBCMath102
Somepossibletrails
• Wecanthinkofseveralwaystogetfromthenesttothefood
(1)AV-shapedanttrail
• WhatisthetotallengthofthisVshapedtrail?
UBCMath102
(2)AT-shapedanttrail:
• WhatisthetotallengthofthisTshapedtrail?
UBCMath102
(3)Whichpathisshorter?
(A) TheVpath.(B) TheTpath.(C)Theyarethesamelength.(D)ItdependsondandD.
UBCMath102
ItdependsondandD!
Example:supposeD=1ThelengthofTpathVpathàLargestdependsond!
Smallvslarged
• larged smalld
(4)Yshapedtrail
Whatisthetotallengthofthetrailshown?
UBCMath102
(5)TheAnttrailproblem
WehavenowfoundthelengthLYoftheY-shapedpath.Whatarewegoingtodonext?
UBCMath102
(6)Whatistherangeofvaluesofx?
Ly(x)=
UBCMath102
Deriva-ve
Usethechainruletofindthederiva-veofthisfunc-on:
UBCMath102
(7)Deriva-veThederiva-veofthefunc-onfortheY-shapedpathlengthis
(8)Cri-calPoints
Thecri-calpointsare:
UBCMath102
Cri-calpoints
• Set
UBCMath102
Annotherwaytogetthesolu-on
Minimalsurfaces(a.k.a.“soapbubbles”)
UBCMath102
Asolu-onbysoap!
Twoflatplexiglassplateswith“pegs”represen-ngthenestandfoodsources:Idea:credittoShawnDesaulniers
Asolu-onbysoap!
Soapbubblesformminimalsurfaces(i.e.shapesthathavethesmallestpossiblesurfaceareaforgivenconstraints:Herethreepegsand2flatplatesformtheconstraintsthatthesoapsurfacehastomeet.
Asolu-onbysoap!
Thepegsandflatplatessetaconstantheightinthezdirec-on:Hencethesoapbubbleselectsaconfigura-onwithshortestlengthinthexyplane
z
xy
Now-metofinishthecalculusproblem(forprac-ce)
UBCMath102
(9)Arewedoneyet?
(A) No,wes-llneedtofindthelengthL(x)atthecri-calpoint.
(B) Nowes-llneedtofindhowfarapartthefoodsourcesare,i.e.solveford
(C) No,weneedtocheckthetypeofcri-calpoint
(D) Yes,wearedone
UBCMath102
Checkingviathesecondderiva-ve
Findthesecondderiva-veofthefunc-onRecallthatthefirstderiva-veis
UBCMath102
Solu-on:
Seeanearlierchain-rulederiva-veproblem,andExample8.5intheM102Notes.(Sowhatdoesthistellus?)
UBCMath102
(10)Whatdoesthistellus?
(A) Thesecondderiva-vecanbeeitherposi-veornega-ve,sothecri-calpointcouldbeofeithertype
(B) Thesecondderiva-veisalwaysposi-vesothecri-calpointisalocalminimum.
(C) Thesecondderiva-veisalwaysposi-vesothecri-calpointisalocalmaximum.
UBCMath102
Sketchingtheoriginalfunc-on
Sketchthefunc-on(Remember,thisisanalterna-vetofirstorsecondderiva-vetestsfordiagnosingacri-calpoint.)
UBCMath102
Sketchingtheoriginalfunc-on
Sketchthefunc-on• Smallx:L≈(D-x)+2d=C-x(straightline,slope-1)
UBCMath102 x
Sketchingtheoriginalfunc-on
Sketchthefunc-on• Smallx:L≈(D-x)+2d=C-x• Largex:L≈(D-x)+2x=D+x(straightline,slope+1)
UBCMath102 x
Sketchingtheoriginalfunc-on
Sketchthefunc-on• Smallx:L≈(D-x)+2d=C-x• Largex:L≈(D-x)+2x=D+xConnectthesesmoothly!verifiesaLOCALMIN
UBCMath102 x
Desmos
• Graphofthefunc-onwithD=1
UBCMath102
Forfurtherstudy:Angles
WhatanglesdoestheYtrailform?Wefoundthat
UBCMath102
Angles
WhatangledoestheYtrailform?Seeifyoucananswerthisfornext-me.
AnswersDatafiRng• 1C• 2C• 3E• 4C
Anttrails• 1D• 2A• 3D• 4B• 5B• 6C• 7E• 8B• 9C• 10B
UBCMath102
Problemstotestyourskill
MC3
Eachofthegraphsrepresentsf(t),theamountoffoodgainedduring-metspentinafoodpatch.Whichofthesegraphsrepresentsthetypeofpatchwherefoodcanbecollectedrapidlyatfirst,butthereisonlysomemaximalamountthatcanbeobtainednomaherhowlongthesearchcon-nues?
UBCMath102
MC5
Theabsolutemaximumofthefunc-ony=f(x)=x+1/xontheinterval0.1≤x≤2occursat
UBCMath102
MC6
Lety=f(x)beasmoothfunc-on(deriva-vesofallordersexist)atx0.Whichofthefollowingstatementsiscorrect?
UBCMath102
Relatedproblems
Prac-cetheChainRule
UBCMath102
Solu-on
UBCMath102
Solu-onstopreviousproblemsFirsttryouttheproblemsattheendofthelastlectureslides.Onlythenshouldyou“peek”attheanswers.
•
Op-malforaging
UBCMath102
Solu-on
Solu-on
HenceQ’(t)=R’(t)(sincepisaconstant).sothatmaximizingQturnsouttobethesameasmaximizingRasdoneinthelecture.Sot=
Moreop-malforaging
•
Solu-on
•
Cannonball
UBCMath102 Solu-on
Solu-on:
Reviewproblem(1)
Solu-on:
UBCMath102
ReviewProblem(2)
Solu-on:
UBCMath102
ReviewProblem(3)
UBCMath102 Solu-on
Solu-onto(3a)
UBCMath102
Solu-onto(3b)
UBCMath102