Code for Electronic Supplement

FindRoots2D

FindRoots2D::usage=
"FindRoots2D[funcs,{x,a,b},{y,c,d}] finds all nontangential solutions to {f=0, g=0} in the given rectangle.";

Options[FindRoots2D]={PlotPoints->Automatic, MaxRecursion->Automatic};

FindRoots2D[funcs_,{x_,a_,b_},{y_,c_,d_},opts___]:=Module[{fZero,seeds,signs,fy},
fy=Compile[{x,y},Evaluate[funcs[[2]]]];
fZero=Cases[Normal[ContourPlot[funcs[[1]]==0,{x,a-((b-a)/97),b+((b-a)/103)},{y,c-((d-c)/98),d+((d-c)/102)},Evaluate[FilterRules[{opts}, Options[ContourPlot]]]]], Line[z_] :> z,∞];
seeds=Flatten[(signs=
Sign[Apply[fy,#,{1}]];#1[[1+Flatten[Position[Rest[signs * RotateRight[signs]],-1]]]])&/@fZero,1];
If[seeds=={},{},Select[Union[
({x,y}/.FindRoot[{funcs[[1]],funcs[[2]]},{x,#[[1]]},{y,#[[2]]},Evaluate[FilterRules[{opts}, Options[FindRoot]]]]&)/@seeds],a≤#[[1]]≤b&&c≤#[[2]]≤d&]]]

Temperature Data

dataMain={{0.,98.2},{1.,94.4},{2.,91.4},{3.,89.1},{4.,86.9},{5.,84.9},{6.,83.1},{7.,81.2},{8.,79.5},{9.,78.},{10.,76.5},{11.,75.2},{12.,73.8},{13.,72.6},{14.,71.4},{15.,70.3},{16.,69.3},{17.,68.2},{18.,67.2},{19.,66.3},{20.,65.3},{21.,64.3},{22.,63.7},{23.,62.9},{24.,62.1},{25.,61.5},{26.,60.7},{27.,60.},{28.,59.4},{29.,58.6},{30.,58.1},{31.,57.4},{32.,56.8},{33.,56.1},{34.,55.6},{35.,55.},{36.,54.5},{37.,54.},{38.,53.5},{39.,53.},{40.,52.5},{41.,52.1},{42.,51.7},{43.,51.3},{44.,50.8},{45.,50.5},{46.,50.},{47.,49.6},{48.,49.2},{49.,48.8},{50.,48.5},{51.,48.1},{52.,47.7},{53.,47.3},{54.,47.},{55.,46.6},{56.,46.3},{57.,46.},{58.,45.7},{59.,45.3},{60.,45.1},{61.,44.7},{62.,44.5},{63.,44.2},{64.,43.8},{65.,43.6},{66.,43.2},{67.,43.},{68.,42.7},{69.,42.5},{70.,42.2},{71.,42.},{72.,41.6},{73.,41.5},{74.,41.2},{75.,41.},{76.,40.7},{77.,40.6},{78.,40.3},{79.,40.2},{80.,40.},{81.,39.5},{82.,39.3},{83.,39.1},{84.,38.8},{85.,38.7},{86.,38.4},{87.,38.2},{88.,38.1},{89.,37.9},{90.,37.7},{91.,37.5},{92.,37.3},{93.,37.1},{94.,37.},{95.,36.8},{96.,36.6},{97.,36.5},{98.,36.3},{99.,36.2},{100.,36.},{101.,35.8},{102.,35.7},{103.,35.6},{104.,35.4},{105.,35.3},{106.,35.1},{107.,35.},{108.,34.9},{109.,34.7},{110.,34.5},{111.,34.4},{112.,34.2},{113.,34.1},{114.,33.9},{115.,33.8},{116.,33.7},{117.,33.5},{118.,33.4},{119.,33.3},{120.,33.2},{121.,33.},{122.,32.9},{123.,32.8},{124.,32.7},{125.,32.6},{126.,32.4},{127.,32.3},{128.,32.2},{129.,32.1},{130.,32.},{131.,31.9},{132.,31.8},{133.,31.7},{134.,31.5},{135.,31.5},{136.,31.4},{137.,31.3},{138.,31.1},{139.,31.1},{140.,31.},{141.,30.9},{142.,30.7},{143.,30.7},{144.,30.6},{145.,30.5},{146.,30.4},{147.,30.3},{148.,30.2},{149.,30.1},{150.,30.1},{151.,30.},{152.,30.},{153.,29.8},{154.,29.8},{155.,29.7},{156.,29.6},{157.,29.5},{158.,29.4},{159.,29.4},{160.,29.2},{161.,29.2},{162.,29.1},{163.,29.},{164.,29.},{165.,28.9},{166.,28.8},{167.,28.7},{168.,28.6},{169.,28.6},{170.,28.5},{171.,28.4},{172.,28.4},{173.,28.3},{174.,28.2},{175.,28.2},{176.,28.1},{177.,28.},{178.,28.},{179.,27.9},{180.,27.8},{181.,27.8},{182.,27.7},{183.,27.7},{184.,27.6},{185.,27.5},{186.,27.5},{187.,27.4},{188.,27.4},{189.,27.3},{190.,27.2},{191.,27.2},{192.,27.1},{193.,27.1},{194.,27.},{195.,27.},{196.,26.9},{197.,26.9},{198.,26.8},{199.,26.8},{200.,26.7},{201.,26.7},{202.,26.6},{203.,26.6},{204.,26.5},{205.,26.5},{206.,26.4},{207.,26.4},{208.,26.4},{209.,26.3},{210.,26.2},{211.,26.2},{212.,26.2},{213.,26.1},{214.,26.1},{215.,26.1},{216.,26.},{217.,26.},{218.,26.},{219.,25.9},{220.,25.9},{221.,25.8}};
dataOil=Take[{{0.`,91.0634763326`},{0.5`,90.7340826047`},{1.`,90.3266982202`},{1.5`,90.084546786`},{2.`,89.7642862899`},{2.5`,89.5260159447`},{3.`,89.2108444279`},{3.5`,89.0543244134`},{4.`,88.8208579188`},{4.5`,88.5889481628`},{5.`,88.3585736188`},{5.5`,88.2058330493`},{6.`,87.9779705165`},{6.5`,87.7515878613`},{7.`,87.6014783501`},{7.5`,87.3775178945`},{8.`,87.1549848315`},{8.5`,87.0074130607`},{9.`,86.7872169729`},{9.5`,86.641186016`},{10.`,86.4232758311`},{10.5`,86.206713343`},{11.`,86.0630784294`},{11.5`,85.8487234359`},{12.`,85.706544375`},{12.5`,85.5649389569`},{13.`,85.3535957542`},{13.5`,85.2134032296`},{14.`,85.0041570317`},{14.5`,84.7961479848`},{15.`,84.6581549567`},{15.5`,84.4521736539`},{16.`,84.3155184717`},{16.5`,84.1115232956`},{17.`,83.9087003308`},{17.5`,83.7741291853`},{18.`,83.5732282878`},{18.5`,83.3734620648`},{19.`,83.2409082175`},{19.5`,83.1088486282`},{20.`,82.9116773844`},{20.5`,82.780836327`},{21.`,82.585474842`},{21.5`,82.3911821893`},{22.`,82.2622413665`},{22.5`,82.0697024191`},{23.`,81.9419193929`},{23.5`,81.7511003827`},{24.`,81.5612975147`},{24.5`,81.4353210437`},{25.`,81.2471860055`},{25.5`,81.1223108721`},{26.`,80.9978704572`},{26.5`,80.8120177899`},{27.`,80.6271250051`},{27.5`,80.5043911201`},{28.`,80.3210744218`},{28.5`,80.1993815367`},{29.`,80.0176119581`},{29.5`,79.8367570648`},{30.`,79.7166903527`},{30.5`,79.5373378035`},{31.`,79.358873635`},{31.5`,79.2403863285`},{32.`,79.06338157`},{32.5`,78.9458584964`},{33.`,78.770287205`},{33.5`,78.6537112904`},{34.`,78.479548181`},{34.5`,78.3639027824`},{35.`,78.191123206`},{35.5`,78.0191621743`},{36.`,77.9049720196`},{36.5`,77.7343563527`},{37.`,77.6210553596`},{37.5`,77.4517619655`},{38.`,77.2832510863`},{38.5`,77.1713412798`},{39.`,77.0041168923`},{39.5`,76.8376539683`},{40.`,76.727097921`},{40.5`,76.5618870786`},{41.`,76.3974174501`},{41.5`,76.2881791601`},{42.`,76.124928506`},{42.5`,76.016496137`},{43.`,75.854444398`},{43.5`,75.693102575`},{44.`,75.5859323195`},{44.5`,75.4257582852`},{45.`,75.3193602261`},{45.5`,75.1603351096`},{46.`,75.001990466`},{46.5`,74.8968021743`},{47.`,74.7395771488`},{47.5`,74.5830153369`},{48.`,74.4790061273`},{48.5`,74.3235356878`},{49.`,74.1687118197`},{49.5`,74.0658521043`},{50.`,73.9120923672`},{50.5`,73.7589631475`},{51.`,73.6572243845`},{51.5`,73.5051330119`},{52.`,73.3536566638`},{52.5`,73.2530113088`},{53.`,73.1025474371`},{53.5`,72.9526836324`},{54.`,72.8531050927`},{54.5`,72.7042292654`},{55.`,72.5559390586`},{55.5`,72.45740165`},{56.`,72.3100757539`},{56.5`,72.1633215198`},{57.`,72.065800426`},{57.5`,71.9199876311`},{58.`,71.7747330061`},{58.5`,71.67820424`},{59.`,71.533868943`},{59.5`,71.3900787697`},{60.`,71.2468289386`},{60.5`,71.1516269071`},{61.`,71.0092671812`},{61.5`,70.9146542461`},{62.`,70.7731717746`},{62.5`,70.6322095958`},{63.`,70.538521648`},{63.5`,70.3984167001`},{64.`,70.2588202243`},{64.5`,70.1197278852`},{65.`,70.0272776176`},{65.5`,69.8890160126`},{66.`,69.797115659`},{66.5`,69.6596731236`},{67.`,69.5227165265`},{67.5`,69.3862417993`},{68.`,69.2955243657`},{68.5`,69.159843843`},{69.`,69.0246345718`},{69.5`,68.9347549376`},{70.`,68.8003224468`},{70.5`,68.666350914`},{71.`,68.5328729473`},{71.5`,68.4441880474`},{72.`,68.3111737319`},{72.5`,68.1789690405`},{73.`,68.0910788893`},{73.5`,67.9596104745`},{74.`,67.8282216695`},{74.5`,67.6976249738`},{75.`,67.6107996322`},{75.5`,67.4805634716`},{76.`,67.3942122796`},{76.5`,67.2650369155`},{77.`,67.1362802917`},{77.5`,67.0503230732`},{78.`,66.9222581456`},{78.5`,66.7946032135`},{79.`,66.6673550659`},{79.5`,66.5824010042`},{80.`,66.4558248826`},{80.5`,66.3716623163`},{81.`,66.245748449`},{81.5`,66.1198854227`},{82.`,65.9947561014`},{82.5`,65.9115518594`},{83.`,65.7867266534`},{83.5`,65.6626243784`},{84.`,65.580100467`},{84.5`,65.4566288668`},{85.`,65.3331960228`},{85.5`,65.2513387123`},{86.`,65.1288607034`},{86.5`,65.0474127982`},{87.`,64.9252125713`},{87.5`,64.8037082991`},{88.`,64.682563803`},{88.5`,64.6019993553`},{89.`,64.4811196486`},{89.5`,64.4009491744`},{90.`,64.2809856649`},{90.5`,64.1610441519`},{91.`,64.0814935862`},{91.5`,63.9624542258`},{92.`,63.8437564093`},{92.5`,63.7250747152`},{93.`,63.6463566143`},{93.5`,63.5677873697`},{94.`,63.4110925654`},{94.5`,63.3326456836`},{95.`,63.2157296147`},{95.5`,63.1379668888`},{96.`,63.0215930385`},{96.5`,62.9052247616`},{97.`,62.8280354531`},{97.5`,62.7125165887`},{98.`,62.6356797627`},{98.5`,62.5203727193`},{99.`,62.4056926477`},{99.5`,62.3294117025`},{100.`,62.2149358074`},{100.5`,62.1389971793`},{101.`,62.0253432439`},{101.5`,61.9119922113`},{102.`,61.8362833426`},{102.5`,61.7234332503`},{103.`,61.648365136`},{103.5`,61.5360093478`},{104.`,61.4236416106`},{104.5`,61.3490963999`},{105.`,61.2375204256`},{105.5`,61.1262328767`},{106.`,61.0518972796`},{106.5`,60.9410868015`},{107.`,60.8673705765`},{107.5`,60.7570309385`},{108.`,60.6466708971`},{108.5`,60.5734528282`},{109.`,60.4638561662`},{109.5`,60.3909445383`},{110.`,60.2815071086`},{110.5`,60.2088989521`},{111.`,60.1002119799`},{111.5`,60.0279033834`},{112.`,59.9193678481`},{112.5`,59.8473559331`},{113.`,59.7395582968`},{113.5`,59.6678392631`},{114.`,59.5601855141`},{114.5`,59.4530852341`},{115.`,59.3818285117`},{115.5`,59.2748662483`},{116.`,59.2038944797`},{116.5`,59.09764838`},{117.`,58.9916546482`},{117.5`,58.9208427392`},{118.`,58.8152665972`},{118.5`,58.7450203497`},{119.`,58.6398565388`},{119.5`,58.5695971202`},{120.`,58.49973321`},{120.5`,58.3951397676`},{121.`,58.2907878202`},{121.5`,58.2210688905`},{122.`,58.1171165874`},{122.5`,58.047946989`},{123.`,57.9443893535`},{123.5`,57.8751992465`},{124.`,57.8063956428`},{124.5`,57.6690982871`},{125.`,57.6006036453`},{125.5`,57.5319310173`},{126.`,57.4295333112`},{126.5`,57.3613945237`},{127.`,57.2593747851`},{127.5`,57.1912086027`},{128.`,57.0895634117`},{128.5`,57.0219236207`},{129.`,56.9206483859`},{129.5`,56.8529779144`},{130.`,56.7520693114`},{130.5`,56.6849179708`},{131.`,56.5843715273`},{131.5`,56.5171863199`},{132.`,56.4503708875`},{132.5`,56.350325648`},{133.`,56.2504927012`},{133.5`,56.1837825879`},{134.`,56.0843010664`},{134.5`,56.0180961023`},{135.`,55.9189617599`},{135.5`,55.852716838`},{136.`,55.7539266153`},{136.5`,55.6881801092`},{137.`,55.622524075`},{137.5`,55.5239404908`},{138.`,55.458509359`},{138.5`,55.3931673878`},{139.`,55.2953207986`},{139.5`,55.2302001148`},{140.`,55.1324175715`},{140.5`,55.0675162501`},{141.`,54.9703272211`},{141.5`,54.905642648`},{142.`,54.8407795784`},{142.5`,54.7440429724`},{143.`,54.6796584641`},{143.5`,54.5832406711`},{144.`,54.5188047838`},{144.5`,54.4227030605`},{145.`,54.3587396399`},{145.5`,54.2948593373`},{146.`,54.1989328609`},{146.5`,54.1352592087`},{147.`,54.0716674926`},{147.5`,53.9764328199`},{148.`,53.9127848672`},{148.5`,53.8178542187`},{149.`,53.7546675425`},{149.5`,53.6915608247`},{150.`,53.5967919802`},{150.5`,53.5338840689`},{151.`,53.4710549883`},{151.5`,53.3769584789`},{152.`,53.3143250857`},{152.5`,53.2515131994`},{153.`,53.1578252156`},{153.5`,53.1266344105`},{154.`,53.033177022`},{154.5`,52.9707127668`},{155.`,52.8775414904`},{155.5`,52.8155218207`},{156.`,52.7535774092`},{156.5`,52.660547986`},{157.`,52.59879071`},{157.5`,52.5371076429`},{158.`,52.4754984884`},{158.5`,52.3832226977`},{159.`,52.3215454427`},{159.5`,52.2601929665`},{160.`,52.1989130852`},{160.5`,52.1071287473`},{161.`,52.0457788317`},{161.5`,51.9847510598`},{162.`,51.9237945925`},{162.5`,51.8324929692`},{163.`,51.7717135287`},{163.5`,51.7107557449`},{164.`,51.6501169531`},{164.5`,51.5592894859`},{165.`,51.5290483846`},{165.5`,51.4381813814`},{166.`,51.3778546436`},{166.5`,51.3175964369`},{167.`,51.2574064911`},{167.5`,51.1972845371`},{168.`,51.1069826585`},{168.5`,51.0470297903`},{169.`,50.9871439806`},{169.5`,50.8974404244`},{170.`,50.8675724833`},{170.5`,50.7778235918`},{171.`,50.7182365688`},{171.5`,50.6587151673`},{172.`,50.5992591301`},{172.5`,50.5396249291`},{173.`,50.4802991182`},{173.5`,50.3914314439`},{174.`,50.3618410373`},{174.5`,50.2731658322`},{175.`,50.2138869034`},{175.5`,50.1549135274`},{176.`,50.0960033712`},{176.5`,50.0077561341`},{177.`,49.9487622861`},{177.5`,49.8900717166`},{178.`,49.8314432631`},{178.5`,49.7728766835`},{179.`,49.7143717365`},{179.5`,49.6851423002`},{180.`,49.5973066346`},{180.5`,49.5389853982`},{181.`,49.4807248392`},{181.5`,49.4225247215`},{182.`,49.3641466551`},{182.5`,49.3060669609`},{183.`,49.2480470047`},{183.5`,49.1900865544`},{184.`,49.103256947`},{184.5`,49.0741063108`},{185.`,48.9874536817`},{185.5`,48.958598746`},{186.`,48.8721213634`},{186.5`,48.8145423461`},{187.`,48.756785499`},{187.5`,48.6993220816`},{188.`,48.6419160103`},{188.5`,48.5845670627`},{189.`,48.5272750175`},{189.5`,48.4698051994`},{190.`,48.4126265293`},{190.5`,48.355504102`},{191.`,48.2984376996`},{191.5`,48.2414271052`},{192.`,48.1842387946`},{192.5`,48.1273393953`},{193.`,48.0704951575`},{193.5`,48.0137058677`},{194.`,47.9569713134`},{194.5`,47.9000590993`},{195.`,47.8434336034`},{195.5`,47.7868622093`},{196.`,47.7303447075`},{196.5`,47.6738808897`},{197.`,47.6172394681`},{197.5`,47.5608826141`},{198.`,47.5045788228`},{198.5`,47.448327889`},{199.`,47.3921296082`},{199.5`,47.3638200437`},{200.`,47.2796604077`},{200.5`,47.2236190805`},{201.`,47.1956178704`},{201.5`,47.1396542318`},{202.`,47.0835130931`},{202.5`,47.0276525493`},{203.`,46.9718431489`},{203.5`,46.9439575656`},{204.`,46.8603769878`},{204.5`,46.8044918345`},{205.`,46.7488852431`},{205.5`,46.6933288128`},{206.`,46.6378223494`},{206.5`,46.5823656597`},{207.`,46.5267315745`},{207.5`,46.4990466542`},{208.`,46.443713759`},{208.5`,46.3884299658`},{209.`,46.3608064229`},{209.5`,46.278008925`},{210.`,46.2226454251`},{210.5`,46.1950948526`},{211.`,46.1400298724`},{211.5`,46.0850129565`},{212.`,46.0300439183`},{212.5`,46.0025772955`},{213.`,45.9200239387`},{213.5`,45.865197617`},{214.`,45.8378021446`},{214.5`,45.7830464624`},{215.`,45.7007767289`},{215.5`,45.6461380582`},{216.`,45.591545798`},{216.5`,45.5369997679`},{217.`,45.5097440331`},{217.5`,45.4552670118`},{218.`,45.4006127879`},{218.5`,45.3734143745`},{219.`,45.2918873179`},{219.5`,45.2647342866`},{220.`,45.2104620729`},{220.5`,45.1560126942`},{221.`,45.1018304596`},{221.5`,45.0476928601`},{222.`,45.0206407441`},{222.5`,44.9665697712`},{223.`,44.9125429995`},{223.5`,44.8853248949`},{224.`,44.8313642818`},{224.5`,44.7774474393`},{225.`,44.7235741964`},{225.5`,44.6697443829`},{226.`,44.642845709`},{226.5`,44.5888604616`},{227.`,44.5351386558`},{227.5`,44.5082938272`},{228.`,44.4546362139`},{228.5`,44.4010211863`},{229.`,44.3472291045`},{229.5`,44.2936989208`},{230.`,44.2669496215`},{230.5`,44.240210823`},{231.`,44.1600572265`},{231.5`,44.1333602253`},{232.`,44.0797787819`},{232.5`,44.0531129983`},{233.`,43.9998124205`},{233.5`,43.9465530264`},{234.`,43.9199387225`},{234.5`,43.8667407999`},{235.`,43.8133658832`},{235.5`,43.7602495245`},{236.`,43.7337065268`},{236.5`,43.6806507944`},{237.`,43.6276352802`},{237.5`,43.5746598251`},{238.`,43.5479701215`},{238.5`,43.495054621`},{239.`,43.4686117543`},{239.5`,43.4421787837`},{240.`,43.362939053`},{240.5`,43.3365454711`},{241.`,43.2835715429`},{241.5`,43.2572073776`},{242.`,43.2045082471`},{242.5`,43.1518479212`},{243.`,43.0992262455`},{243.5`,43.0464276401`},{244.`,43.0464276401`},{244.5`,42.9938829603`},{245.`,42.9413764699`},{245.5`,42.8889080163`},{246.`,42.8364774476`},{246.5`,42.8102763227`},{247.`,42.7576877272`},{247.5`,42.7315148659`},{248.`,42.6791971981`},{248.5`,42.6530523541`},{249.`,42.600790552`},{249.5`,42.548565807`},{250.`,42.5222534001`},{250.5`,42.4700841123`},{251.`,42.4440132345`},{251.5`,42.4179515095`},{252.`,42.3398210667`},{252.5`,42.3137957686`},{253.`,42.2877795312`},{253.5`,42.2355611031`},{254.`,42.1835919086`},{254.5`,42.1316585916`},{255.`,42.1057053417`},{255.5`,42.0797610067`},{256.`,42.0278990091`},{256.5`,41.9758601233`},{257.`,41.9499601643`},{257.5`,41.8981866483`},{258.`,41.8464482155`},{258.5`,41.8205921106`},{259.`,41.794744723`},{259.5`,41.7430760283`},{260.`,41.7170430712`},{260.5`,41.6654264485`},{261.`,41.6396310621`},{261.5`,41.5880660509`},{262.`,41.5365352713`},{262.5`,41.5107826745`},{263.`,41.4590920666`},{263.5`,41.4333650026`},{264.`,41.4076463913`},{264.5`,41.3562344573`},{265.`,41.3048561259`},{265.5`,41.3048561259`},{266.`,41.2535112584`},{266.5`,41.2019894919`},{267.`,41.1763462431`},{267.5`,41.1250845673`},{268.`,41.0738558732`},{268.5`,41.0482538514`},{269.`,41.0226600237`},{269.5`,40.9712872648`},{270.`,40.9457179841`},{270.5`,40.8946037837`},{271.`,40.8690588302`},{271.5`,40.817993132`},{272.`,40.7924723536`},{272.5`,40.7414548541`},{273.`,40.7159580994`},{273.5`,40.6902604276`},{274.`,40.6647796701`},{274.5`,40.6138419609`},{275.`,40.5883849758`},{275.5`,40.5374946616`},{276.`,40.4866357779`},{276.5`,40.4610097716`},{277.`,40.4101979132`},{277.5`,40.3848036545`},{278.`,40.3594171544`},{278.5`,40.3086673636`},{279.`,40.2833040402`},{279.5`,40.2579484096`},{280.`,40.2326004556`},{280.5`,40.1563949386`},{281.`,40.1310775899`},{281.5`,40.1057678361`},{282.`,40.0804656612`},{282.5`,40.0551710488`},{283.`,40.0046044471`},{283.5`,39.9793324255`}},443];

Differential Equations

Code for COA

Show[nullclineRegions,Graphics[{PointSize[0.03],Yellow, Point[eq]}],orbits,FrameTicks->{Range[-4π,4π,2π],Range[-4π,4π,2π],None, None}]

.  Solving Differential Equations

sol=DSolve[x'[t]==x[t],x[t],t]

x[t]/.First[sol]/.C[1]->K

x[t]/.First[DSolve[{x'[t]==x[t],x[0]==2},x[t],t]]

x[t]/.First[DSolve[x'[t]==2 x[t]+Cos[t],x[t],t]]

{x[t],y[t]}/.First[DSolve[{x'[t]==2 y[t]-x[t],y'[t]==-x[t]+y[t]},{x[t],y[t]},t]]

iFcn=Interpolation[Table[{θ, Sin[θ]},{θ, 0, 4π, π/2}]]

Plot[{iFcn[t], Sin[t]}, {t,0,4π}]

Plot[Evaluate[{Cos[t],D[iFcn[t],t]}], {t,0,4π}]

sol=x[t]/.NDSolve[{x'[t]+t ((Cos[π t])^2) x[t]==t Cos[t],x[0]==0},x[t],{t,0,10}][[1]]

Plot[Evaluate[sol],{t,0,10}]

soln=x[t]/.First[NDSolve[{x'[t]+t ((Cos[π t])^2) x[t]==t Cos[t],x[0]==0},x[t],{t,0,10}]]

x/.First[NDSolve[{x'[t]+t ((Cos[π t])^2) x[t]==t Cos[t],x[0]==0},x,{t,0,10}]]

FindRoot[soln==-3,{t,10}]

Plot[Evaluate[(∂_t)soln+t ((Cos[π t])^2) soln-t Cos[t]],{t,0,10},PlotRange->{-0.001,0.001},Frame->True]

.  Stylish Plots

tmax=700;
soln={x[1][t],x[2][t],x[3][t],x[4][t]}/.NDSolve[{(x[1])'[t]==-0.002 x[1][t],(x[2])'[t]==0.4 x[1][t]-0.08 x[2][t]-x[2][t] ((x[3][t])^2),(x[3])'[t]==-x[3][t]+0.08 x[2][t]+x[2][t] ((x[3][t])^2),(x[4])'[t]==0.005 x[3][t],x[1][0]==2.5,x[2][0]==0,x[3][0]==0,x[4][0]==0},Table[x[i][t],{i,1,4}],{t,0,tmax}]

m1=700/40;m2=3.3/30;
Plot[Evaluate[First[soln]],{t,0,tmax},PlotRange->{{-m1,tmax+m1},{-m2,3.3+m2}},
	  PlotStyle->{{Green,Thick},{Yellow,Thickness[0.003]},{Red,Thickness[0.003]},{Cyan,Thick}},
	FrameLabel->{"Time","Concentrations"},Frame->True,Prolog->{{Thickness[0.002],Gray,Rectangle[{0,0},{tmax,3.3}]}},
	FrameTicks->{Range[0,700,100],Range[0,3], None, None}, PlotRangeClipping->False]

soln=x[t]/.First[NDSolve[{x''[t]==-x'[t]-10 Sin[x[t]],x[0]==-14,x'[0]==15},x[t],{t,0,15}]]

ParametricPlot[Evaluate[{soln,D[soln,t]}],{t,0,15},PlotRange->{{-15,10},{-10,15}}]

initial=Join[Table[{x,15},{x,-14,-7,0.5}],Table[{x,-15},{x,7.6,14,0.8}]];
solns=Table[x[t]/.First[NDSolve[{x''[t]==-x'[t]-10 Sin[x[t]],x[0]==iv[[1]],x'[0]==iv[[2]]},x[t],{t,0,15}]], {iv,initial}];
orbits=ParametricPlot[Evaluate[Transpose[{solns,D[solns,t]}]],{t,0,15},PlotRange->{{-15,15},{-15,15}},Frame->True,Axes->None, PlotStyle->Table[{ColorData["Rainbow"][i/24],Thickness[0.004]}, {i,24}], FrameTicks->{Range[-4π,4π,2π],Range[-4π,4π,2π], None, None}]

Clear[soln];
soln[iv_]:=x[t]/.First[NDSolve[{x''[t]==-x'[t]-10 Sin[x[t]],x[0]==iv[[1]],x'[0]==iv[[2]]},x[t],{t,0,15}]];
Manipulate[sol=soln[iv];
ParametricPlot[Evaluate[{sol,D[sol,t]}],{t,0,15},PlotRange->{{-15,15},{-15,15}},
Frame->True,Axes->True, PlotStyle->Thick], {{iv, {1,10}}, Locator}]

{f,g}={y,-y-10 Sin[x]};
nullclines=ContourPlot[{f==0,g==0},{x,-15,15},{y,-15,15},ContourStyle->{Directive[Thick,Black],Directive[Thick,Black]}];
Show[nullclines,orbits,PlotRange->{{-15,15},{-15,15}}]

nullclineRegions=RegionPlot[{f≥0&&g≥0,f≤0&&g≥0,f≥0&&g≤0,f≤0&&g≤0},{x,-15,15},{y,-15,15},PlotStyle->Nest[Lighter,{Red,Green,Blue,Cyan},3],BoundaryStyle->{Thickness[0.003]}, PlotPoints->30]

initial=Join[Table[{x,15},{x,-14,-7,0.5}],Table[{x,-15},{x,7.6,14,0.8}]];
solns=Table[x[t]/.First[NDSolve[{x''[t]==-x'[t]-10 Sin[x[t]],x[0]==iv[[1]],x'[0]==iv[[2]]},x[t],{t,0,15}]], {iv,initial}];
orbits=ParametricPlot[Evaluate[Transpose[{solns,D[solns,t]}]],{t,0,15},PlotRange->15,Frame->True,Axes->None, PlotStyle->{{Red,Thickness[0.003]}}];
Show[nullclineRegions,orbits,FrameTicks->{Range[-4π,4π,2π],Range[-10,10,5],None, None}]

eq=FindRoots2D[{f,g},{x,-15,15},{y,-15,15}]

Show[nullclineRegions,Graphics[{PointSize[0.03],Yellow, Point[eq]}],orbits,FrameTicks->{Automatic,Automatic,None, None}]

Clear[soln];
soln[iv_]:=x[t]/.First[NDSolve[{x''[t]==-x'[t]-10 Sin[x[t]],x[0]==iv[[1]],x'[0]==iv[[2]]},x[t],{t,0,15}]];
Manipulate[sol=soln[iv];
Show[nullclineRegions,Graphics[{PointSize[0.03],Yellow, Point[eq]}],ParametricPlot[Evaluate[{sol,D[sol,t]}],{t,0,15}, PlotStyle->{Thick, Red}],PlotRange->15,
Frame->True,Axes->False], {{iv, {0,3}}, Locator}]

solns=Table[x[t]/.First[NDSolve[{(x')'[t]==Cos[t]-Sin[x[t]]-0.1 x'[t],x[0]==0,x'[0]==y0},x[t],{t,0,200}]],{y0,1.85,2.1,0.025}];

Plot[Evaluate[solns],{t,0,200},Frame->True, PlotStyle->Thick,PlotRange->{-35,28}]

sol=x[t]/.First[NDSolve[{(x')'[t]==Cos[t]-Sin[x[t]]-0.1 x'[t],x[0]==0,x'[0]==1.85},x[t],{t,0,100}]];
ParametricPlot[Evaluate[{sol, D[sol,t]}],{t,0,100},Frame->True,PlotStyle->Thick, ColorFunction->(Hue[#3]&)]

P[{a_?NumericQ,b_?NumericQ},tmax_]:={x[tmax],y[tmax]}/.First[NDSolve[
Join[{y'[t]==Cos[t]-Sin[x[t]]-0.1 y[t],x'[t]==y[t]},{x[0]==a,y[0]==b}],{x,y},{t,0,tmax}]]

distances=Table[{b,Abs[Norm[P[{-2,b},50]]-Norm[P[{-2,b+0.001},50]]]},{b,0,1.1,0.01}];
ListLinePlot[distances,Frame->True,PlotRange->All, Axes->False, PlotStyle->Thick]

distancedifference[b_Real]:=Abs[Norm[P[{-2,b},50]]-Norm[P[{-2,b+0.001},50]]];
separatingPt={-2.0,b}/.Last[FindMaximum[distancedifference[b],{b,0.8,0.9}]]

Find4πPeriodic[{a_,b_}]:={xx,yy}/.FindRoot[P[{xx,yy},4 π]=={xx,yy},{xx,a},{yy,b}]
p=Find4πPeriodic[separatingPt]

sol=x[t]/.First[NDSolve[{(x')'[t]==Cos[t]-Sin[x[t]]-0.1 x'[t],x[0]==p[[1]],x'[0]==p[[2]]},x[t],{t,0,40}]];
Plot[Evaluate[sol],{t,0,40},Frame->True,PlotStyle->Thick]

sol=x[t]/.First[NDSolve[{(x')'[t]==Cos[t]-Sin[x[t]]-0.1 x'[t],x[0]==p[[1]],x'[0]==p[[2]]},x[t],{t,0,40}]];
ParametricPlot[Evaluate[{sol, D[sol,t]}],{t,0,40},Frame->True,PlotStyle->Thick]

.  Pitfalls of Numerical Computing

soln=x[t]/.First[NDSolve[{x'[t]==2 x[t]+Cos[t],x[0]==-(2/5)},x[t],{t,0,3 π}]];
Plot[Evaluate[soln],{t,0,3 π},PlotRange->All]

trueSoln=x[t]/.First[DSolve[{x'[t]==2 x[t]+Cos[t],x[0]==-(2/5)},x[t],t]]

Plot[trueSoln,{t,0,3 π}]

Duffing[a_,b_,c_,d_]:=x''[t]-a x[t]+b ((x[t])^3)+c x'[t]==d Cos[t]

soln=x[t]/.First[NDSolve[{Duffing[1,1,0.15,0.3],x[0]==1,x'[0]==-1},x[t],{t,0,100}]];ParametricPlot[Evaluate[{soln,D[soln,t]}],{t,0,100}, Frame->True,Axes->None,ColorFunction -> (Hue[#3]&)]

ε=(10^(-8));
solnPerturbed=x[t]/.First[NDSolve[{Duffing[1,1,0.15,0.3],x[0]==1+ε,x'[0]==-1+ε},x[t],{t,0,100}]];
Plot[{soln,solnPerturbed},{t,0,100},Frame->True,PlotStyle->{{Thickness[0.02],Gray},{{Thickness[0.01],Red}}}]

soln=x[t]/.First[NDSolve[{Duffing[1,1,(15/100),(3/10)],x[0]==1,x'[0]==-1},x[t],{t,0,100},WorkingPrecision->18,PrecisionGoal->8]];
ε=(10^(-8));
solnPerturbed=x[t]/.First[NDSolve[{Duffing[1,1,(15/100),(3/10)],x[0]==1+ε,x'[0]==-1+ε},x[t],{t,0,100},WorkingPrecision->20,PrecisionGoal->10]];
Plot[{soln,solnPerturbed},{t,0,100},Frame->True,PlotStyle->{{Thickness[0.02],Gray},{{Thickness[0.01],Red}}}]

soln=x[t]/.First[NDSolve[{x''[t]==((x'[t])^2)-x[t],x[0]==14,x'[0]==0},x[t],{t,0,16.5}]];

ParametricPlot[Evaluate[{soln,D[soln,t]}],{t,0,16.5}]

soln=x[t]/.First[NDSolve[{x''[t]==((x'[t])^2)-x[t],x[0]==14,x'[0]==0},x[t],{t,-16.5,16.5}]];
ParametricPlot[Evaluate[{soln,D[soln,t]}],{t,-16.5,16.5},PlotStyle->Thickness[0.01],Frame->True,ColorFunction->(If[#3>0,Blue,Red]&),ColorFunctionScaling->False,FrameTicks->{Automatic,Automatic,None,None},Epilog->{PointSize[0.04],Point[{14,0}]}]

soln=x/.First[NDSolve[{x''[t]==((x'[t])^2)-x[t],x[0]==14,x'[0]==0},x,{t,0,16.5}]];
backsoln=x/.First[NDSolve[{x''[t]==((x'[t])^2)-x[t],x[16.5]==soln[16.5],x'[16.5]==soln'[16.5]},x,{t,16.5,0}]];

{backsoln[0], soln[0]}

PolkingOrbit[x0_]:=ContourPlot[(2 x0+1) (E^(2 (x-x0)))-2 x-1+2 (y^2)==0,{x,-3,20},{y,-5,5}]
Show[PolkingOrbit/@{-3,-2,-1,-0.7,-0.6,-0.53,-0.52,-0.51,-0.5,0.3,0.5,1,2,3,4,6,8,10,12,14,16,18,20},Epilog->{PointSize[0.01],Point[{0,0}]}]

.  Basins of Attraction

Duffing={x'[t]==y[t],y'[t]==0.5 x[t]-0.5 ((x[t])^3)-0.015 y[t]};

{x,y}/.Solve[Thread[(Last/@Duffing/.a_[t]:>a)=={0,0}],{x,y}]

twoSolns=({x[t],y[t]}/.First[NDSolve[{Duffing,x[0]==#[[1]],y[0]==#[[2]]},{x[t],y[t]},{t,0,100}]]&)/@{{1,0.54},{1,0.56}};
ParametricPlot[Evaluate[twoSolns],{t,0,100},Frame->True, Axes->None, PlotRange->{{-1.6,1.6},{-0.65, 0.65}}]

separatrix=({x[t],y[t]}/.First[NDSolve[{Duffing,x[0]==#1[[1]],y[0]==#1[[2]]},{x[t],y[t]},{t,-133,0}]]&)/@{{0,-0.001},{0,0.001}};

sepPlot=Show[ParametricPlot[Evaluate[separatrix[[1]]],{t,-132.6,0}],ParametricPlot[Evaluate[separatrix[[2]]],{t,-129.5,0}],
	Axes->None,Frame->True]

data=Cases[sepPlot,_Line,∞]/.Line->List;
Short[data,5]

Graphics[{Yellow, Rectangle[{-1.7, -1},{1.7,1}],Blue,Polygon[Join[data[[1,1]],Reverse[data[[2,1]]]]],
PointSize[0.02],{GrayLevel[1],Point[{1,0}]},Point[{-1,0}]},Frame->True, FrameTicks->{Automatic, Automatic, None, None},
PlotRange->{{-1.7,1.7}, {-1, 1}}, PlotRangeClipping->True]

DuffingForced={x'[t]==y[t],y'[t]==x[t]-((x[t])^3)-0.25 y[t]+ 0.25 Cos[t]};

Plot[Evaluate[x[t]/.First[
NDSolve[{DuffingForced,x[0]==1,y[0]==1.1},{x[t],y[t]},{t,0,150}]]], {t,0, 150}]

tmax=8 π;
AttractingWell[a_,b_]:=Sign[x[t]]/.First[NDSolve[{DuffingForced,x[0]==a,y[0]==b},{x[t],y[t]},{t,0,tmax}]]/.t->tmax;

DensityPlot[AttractingWell[a,b],{a,-2.5,2.5},{b,-2.5,2.5},PlotPoints->130,MaxRecursion->3,Mesh->False,ColorFunction->(If[#≠1,Blue,Yellow]&),FrameTicks->{Range[-2,2], Range[-2,2],None,None}]

.  Modeling

Fly me to the moon

p=27.3;R=0.0167;c=0.15;tmax=30;

Moon[t_?NumericQ]:={Cos[((2 π t)/p)],Sin[((2 π t)/p)]};

sol=X[t]/.NDSolve[{X'[t]==((c (Moon[t]-X[t]))/(Norm[Moon[t]-X[t]])),X[0]=={R,0}},X[t],{t,0,tmax}][[1]]

ParametricPlot[sol,{t,0,tmax},Prolog->{{Red,Circle[{0,0},((c p)/(2 π))],Green,PointSize[Large],Point[{{0,0},Moon[tmax]}],Black,Circle[]}},PlotStyle->Thick,PlotRange->1.1,Axes->False,Frame->True]

c=0.25;
sol=X[t]/.NDSolve[{X'[t]==((c (Moon[t]-X[t]))/(Norm[Moon[t]-X[t]])),X[0]=={R,0}},X[t],{t,0,tmax},Method->{"EventLocator","Event":>Norm[Moon[t]-X[t]]-0.01,"EventAction":>Throw[tmaxfound=t,"StopIntegration"]}]
tmaxfound

ParametricPlot[sol,{t,0,tmaxfound},Prolog->{{Green,Disk[{0,0},R],  PointSize[Large],Point[{{0,0},Moon[tmaxfound]}],Black,Circle[]}}, PlotStyle->Thick, PlotRange->1.1, Axes->False, Frame->True]

G=M=1;e=0.5;
soln=X[t]/.NDSolve[{X''[t]==-((G M X[t])/((Norm[X[t]])^3)),X[0]=={1-e,0},X'[0]=={0,(Sqrt[((G M (1+e))/(1-e))])}},X[t],{t,0,2 π}][[1]];
ParametricPlot[soln,{t,0,2 π}, PlotStyle->Thick]

Bicycle tracks

front[t_]:={t,Sin[t]};
F[t_?NumericQ]:=front[t];
Fder[t_?NumericQ]:=Evaluate[front'[t]]
bikeEqn=(X'[t]-Fder[t]==(Fder[t] .(X[t]-F[t]))(X[t]-F[t])-Fder[t])

backSol=X[t]/.NDSolve[{bikeEqn,X[0]=={-1,0}},X[t],{t,0,12}][[1]]

ParametricPlot[{front[t],backSol}, {t,0,12}, Frame->True, Axes->False, PlotStyle->{{Red, Thick}, {Blue, Thick}}, PlotRange->{{-1.2,10},{-1.2,1.2}}, FrameTicks->{Range[10], Range[-1,1], None, None}]

front[t_]:={t,(3/4) Sin[t]+(1/10) Cos[2 t-Sin[t]]};
F[t_?NumericQ]:=front[t];
Fder[t_?NumericQ]:=Evaluate[front'[t]]
bikeEqn=X'[t]-Fder[t]==Fder[t].(X[t]-F[t]) (X[t]-F[t])-Fder[t];
backSol=X[t]/.NDSolve[{bikeEqn,X[0]=={-1,0}},X[t],{t,0,4 π}][[1]];
ParametricPlot[{front[t],backSol},{t,0,4 π},Frame->True,FrameTicks->None, Axes->False,PlotStyle->{{Red,Thick},{Blue,Thick}},PlotRange->({{1,4 π-1},{-1.2,1}})]

The ups and downs of a helium balloon

(Subscript[F, h])=g·(massairdisplaced-masshelium)=(13·1.161-13·0.16)g=13g grams cm/(sec^2).

g=980;ρ=0.1;(Subscript[W, b])=3;
(Subscript[F, w])=-g ((Subscript[W, b])+ρ y[t]);
(Subscript[F, h])=13 g;
(Subscript[F, ground])=If[y'[t]<0,ρ  ((y'[t])^2),0];
(Subscript[F, r])=0;

balloonEqn=(D[((Subscript[W, b])+ρ  y[t]) y'[t],t]==(Subscript[F, h])+(Subscript[F, w])+(Subscript[F, ground])+(Subscript[F, r]))

sol1=y[t]/.NDSolve[{balloonEqn,y[0]==5,y'[0]==0},y[t],{t,0,50}][[1]]

ParametricPlot[Evaluate[{sol1, D[sol1, t]}], {t, 0,50}, AspectRatio->1, PlotRange->{{0, 200}, {-275,275}}, PlotStyle->Thick, Frame->True, FrameLabel->{"Balloon height","Balloon speed"}, RotateLabel->!False]

(Subscript[F, r])=-20 y'[t];
balloonEqn=(D[((Subscript[W, b])+ρ  y[t]) y'[t],t]==(Subscript[F, h])+(Subscript[F, w])+(Subscript[F, ground])+(Subscript[F, r]));
sol2=y[t]/.NDSolve[{balloonEqn,y[0]==5,y'[0]==0},y[t],{t,0,50}][[1]];
ParametricPlot[Evaluate[{sol2, D[sol2, t]}], {t, 0,50}, AspectRatio->1, PlotRange->{{0, 200}, {-275,275}}, PlotStyle->Thick, Frame->True, FrameLabel->{"Balloon height","Balloon speed"}, RotateLabel->!False]

Modeling cooling water

Needs["Units`"];

CToK[z_]:= ConvertTemperature[z,Celsius,Kelvin];
FToK[z_]:= ConvertTemperature[z,Fahrenheit,Kelvin];

dataMainK=dataMain/.{t_,T_}:>{60 t,CToK[T]};dataOilK=dataOil/.{t_,T_}:>{60 t,CToK[T]};
ambientK=CToK[22.7];
ambientOilK=CToK[22.85];

ListPlot[{dataMainK, dataOilK}, Frame->True, PlotStyle->{{Red,Thick}, {Blue, Thick}},FrameTicks->{Range[3000,12000,3000],Automatic,  None ,Append[{FToK[#],#}&/@ Range[50,200,50], {ambientK,"ambient"}]}, Axes->False,PlotRange-> {270, 370}, FrameLabel->{"Time (secs)", "Temperature (K)",None, "Temperature (F)"}, GridLines->{{},{ambientK}}]

times=First/@dataMainK;
temps=Last/@dataMainK;{t0,tmax}=times[[{1,-1}]];

modelDE[k_]:={T'[t]==-k (T[t]-ambientK),T[t0]==temps[[1]]};
Tsol[k_?NumericQ]:=T[t]/.NDSolve[modelDE[k],T[t],{t,t0,tmax}][[1]];
residual[k_?NumericQ]:=((Norm[(Tsol[k]/.t->times)-temps])^2);

Plot[residual[k], {k,0,0.001}, PlotStyle->Thick, Frame->True,FrameTicks->{{0.0001,0.0004,0.0008},{10000, 50000}, None, None}, PlotRange->{0,60000},FrameLabel->{"Conduction coefficient", "Sum squared error"}]

opt=FindMinimum[residual[k],{k,0,1}];
((opt[[1]])/(Length[dataMain]))

kSol=k/.opt[[2]]

Show[Plot[Evaluate[Tsol[kSol]],{t,t0,tmax}, PlotStyle->{Thickness[0.03 ],Orange}],ListPlot[dataMainK, PlotStyle->{PointSize[0.004],Black}],Frame->True, Axes->False,
FrameTicks->{ Range[3000,12000,3000],Range[300,380,20], None ,{FToK[#],#}&/@ Range[50,200,50]}, Axes->False,FrameLabel->{"Time (secs)", "Temperature (K)",None, "Temperature (F)"}]

timesOilK=First/@dataOilK;tempsOilK=Last/@dataOilK;
{t0,tmax}=timesOilK[[{1,-1}]];
modelDEOil[k_]:={T'[t]==-k (T[t]-ambientOilK),T[t0]==tempsOilK[[1]]};
TsolOil[k_?NumericQ]:=T[t]/.NDSolve[modelDEOil[k],T[t],{t,t0,tmax}][[1]];
residualOil[k_?NumericQ]:=((Norm[(TsolOil[k]/.t->timesOilK)-tempsOilK])^2);

optOil=FindMinimum[residualOil[k],{k,0, 1}];
((optOil[[1]])/(Length[dataOilK]))
kSolOil=k/.optOil[[2]]

Show[Plot[Evaluate[TsolOil[kSolOil]],{t,t0,tmax},PlotStyle->{Thickness[0.02],Orange}],ListPlot[dataOilK,PlotStyle->{PointSize[0.004],Black}],Frame->True,FrameTicks->{Range[3000,12000,3000],Range[300,380,20],None,({FToK[#],#}&)/@Range[50,200,50]},Axes->False,FrameLabel->{"Time (secs)","Temperature (K)",None,"Temperature (F)"},PlotRange->{ambientOilK,1.02 tempsOilK[[1]]}]

modelDEWithRadiation[k_]:={T'[t]==-k (T[t]-ambientOilK)-((2.2207 (((T[t])^4)-(ambientOilK^4)))/(10^13)),T[t0]==tempsOilK[[1]]};
TsolWithRadiation[k_?NumericQ]:=T[t]/.NDSolve[modelDEWithRadiation[k],T[t],{t,t0,tmax}][[1]];
residualWithRadiation[k_?NumericQ]:=((Norm[(TsolWithRadiation[k]/.t->timesOilK)-tempsOilK])^2);
optRad=FindMinimum[residualWithRadiation[k],{k,.001,0.005},AccuracyGoal->3];
kSolWithRadiation=k/.optRad[[2]];
((optRad[[1]])/(Length[dataOilK]))

Show[Plot[Evaluate[TsolWithRadiation[kSolWithRadiation]],{t,t0,tmax},PlotStyle->{Orange,Thickness[.02]}],ListPlot[dataOilK,PlotStyle->{PointSize[0.004],Black}],Frame->True,Axes->False,FrameLabel->{"Time (secs)","Temperature (K)",None,"Temperature (F)"},FrameTicks->{Range[3000,12000,3000],Range[300,380,20],None,({FToK[#],#}&)/@Range[50,200,50]},PlotRange->{{0,tmax},{ambientOilK,1.02 tempsOilK[[1]]}}]