Wykład 6 Równania różniczkowe, funkcje DSolve oraz NDSolve. Wykres fazowy. Prawo Hooke a, drgania sprężyn. Ruch z oporem powietrza. In[1]:= ClearAll["Global`*"] wyczyść wszystko Prawo Hooke a Robert Hooke In[2]:= WolframAlpha["Robert Hooke"] zapytaj WolframAlpha Input interpretation: Robert Hooke (scientist) Basic information: Local historical calendar full name date of birth place of birth date of death place of death Robert Hooke Saturday, July 18, 1635 (Julian calendar) (382 years ago) Freshwater, Isle of Wight, United Kingdom Wednesday, March 3, 1703 (Julian calendar) (age: 67 years) (314 years ago) London, Greater London, United Kingdom Image: Timeline: Robert Hooke Include today 1640 1660 1680 1700
2 wyklad6_2017_notes.nb Notable facts: Out[2]= Scientist, accomplished in many fields and invented new instruments such as the first reflecting telescope Formulated Hooke's law stating that the extension of a spring is directly proportional to the mass of an attached load Surveyed much of London after the Great Fire of 1666 and designed many buildings constructed to replace those lost Assisted Robert Boyle in experiments to formulate gas laws, building the vacuum pumps used Early proponent of the theory of biological evolution Scientific contributions: Physics: Hooke's law massive ball massive sphere point mass spring pendulum Inventions: balance wheel (1658) diaphragm universal joint (1545) Wikipedia summary: Robert Hooke FRS (28 July [O.S. 18 July] 1635 3 March 1703) was an English natural philosopher architect and polymath. Full entry» Wikipedia page hits history: Log scale 7000 6000 5000 4000 3000 2000 1000 0 2008 2010 2012 2014 2016 (in hits per day) (based on weekly averages of daily hits to English-language "Robert Hooke" page) Prawo Hooke a In[3]:= WolframAlpha["Hooke's law"] zapytaj WolframAlpha
wyklad6_2017_notes.nb 3 Assuming Hooke's law is referring to a physical principle Use as a formula or a word instead Input interpretation: Hooke's law (physical principle) Description: The extension of a spring is directly proportional to the force applied. Alternate description: Strain is directly proportional to stress. Alternate name: Hooke's law of elasticity Out[3]= History: More discovery date discoverer 1660 (357 years ago) Robert Hooke Associated equation: F -kx Limitations: Applies to linear-elastic materials for forces that do not exceed the elastic limit. Class: laws of physics
4 wyklad6_2017_notes.nb Thomas Young In[4]:= WolframAlpha["Thomas Young"] zapytaj WolframAlpha Input interpretation: Thomas Young (medical researcher, etc.) Basic information: full name date of birth date of death place of death Thomas Young Sunday, June 13, 1773 (244 years ago) Sunday, May 10, 1829 (age: 55 years) (188 years ago) London, Greater London, United Kingdom Image: Out[4]= Timeline: Thomas Young Include today 1780 1790 1800 1810 1820 1830 Wikipedia page hits history: Log scale 500 400 300 200 100 0 2008 2010 2012 2014 2016 (in hits per day) (based on weekly averages of daily hits to English-language "Thomas Young" page)
wyklad6_2017_notes.nb 5 Moduł Young a In[5]:= WolframAlpha["Young's zapytaj WolframAlpha Modulus"] modulo Assuming Young's Modulus is a physical quantity Use as a formula instead Input interpretation: Young's modulus (physical quantity) Common symbol: E Out[5]= Basic dimensions: [mass] [length] -1 [time] -2 Standard unit for Young's modulus: Pa (pascal) Usage type: scalar Alternate description: tensile modulus
6 wyklad6_2017_notes.nb Drgania: dwa ciężarki na sprężynach Wstęp m 1 m 2 In[6]:= k 1 k 12 k 2 x 1 x 2 Niech x 1 oznacza wychylenie ciężarka m 1 z położenia równowagi, po lewej stronie ciężarka x 1 jest dodatnie, a po prawej ujemne; Niech x 2 oznacza wychylenie ciężarka m 2 z położenia równowagi; Na ciało o masie m 1 działa siła : -k 1 x 1 - k 12 (x 1 - x 2 ) Na ciało o masie m 2 działa siła : -k 2 x 2 - k 12 (x 2 - x 1 ) Mamy równania m 1 d 2 x 1 dt 2 +k 1 x 1 + k 12 (x 1 - x 2 )=0 m 2 d 2 x 2 dt 2 +k 2 x 2 + k 12 (x 1 - x 2 )=0 Możemy wpisać do zmiennej $Assumptions globalne założenia, które będą używane, przez funkcję typu Simplify In[6]:= $Assumptions = m1 > 0 && m2 > 0 && k1 > 0 && k2 > 0 && k12 > 0 domyślne założenia Out[6]= m1 > 0 m2 > 0 k1 > 0 k2 > 0 k12 > 0 In[7]:=?? $Assumptions $Assumptions is the default setting for the Assumptions option used in such functions as Simplify, Refine, and Integrate. $Assumptions = m1 > 0 && m2 > 0 && k1 > 0 && k2 > 0 && k12 > 0 In[8]:= Clear[x1, x2] wyczyść
wyklad6_2017_notes.nb 7 In[9]:= DSolve m1 x1''[t] + k1 x1[t] + k12 x1[t] - x2[t] == 0, rozwiązywanie równań różniczkowych m2 x2''[t] + k2 x2[t] + k12 x2[t] - x1[t] == 0, x1[0] == 0, x2[0] == a, x1'[0] == 0, x2'[0] == 0, {x1[t], x2[t]}, t ; FullSimplify[%, Assumptions {k1 > 0, k2 > 0, k12 > 0, a > 0}] uprość pełniej założenia
8 wyklad6_2017_notes.nb Out[10]= x1(t) a k12 m2 cosh -k2 m1 - k1 m2 - k12 (m1 + m2) + (k12 + k2) 2 m1 2-2 ((k1 - k12) k12 + (k1 + k12) k2) m2 m1 + (k1 + k12) 2 m2 2 t 2 m1 m2 - cosh -k2 m1 - k1 m2 - k12 (m1 + m2) - (k12 + k2) 2 m1 2-2 ((k1 - k12) k12 + (k1 + k12) k2) m2 m1 + (k1 + k12) 2 m2 2 t 2 m1 m2 (k12 + k2) 2 m1 2-2 (k12 (k2 - k12) + k1 (k12 + k2)) m2 m1 + (k1 + k12) 2 m2 2, x2( t) a e - -k2 m1-k1 m2-k12 (m1+m2)- (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) k2) m2 m1+(k1+k12) 2 m2 2 + -k2 m1-k1 m2-k12 (m1+m2)+ (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) 2 m1 m2 e -k2 m1-k1 m2-k12 (m1+m2)+ (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) k2) m2 m1+(k1+k12) 2 m2 2 t 2 m1 m2 (k12 + k2) m1 - k1 m2 - k12 m2 + (k12 + k2) 2 m1 2-2 (k12 (k2 - k12) + k1 (k12 + k2)) m2 m1 + (k1 + k12) 2 m2 2 + 2 -k2 m1-k1 m2-k12 (m1+m2)- (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) k2) m2 m1+(k1+k12) 2 m2 2 + -k2 m1-k1 m2-k12 (m1+m2)+ (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k e 2 m1 m2 (k12 + k2) m1 - k1 m2 - k12 m2 + (k12 + k2) 2 m1 2-2 (k12 (k2 - k12) + k1 (k12 + k2)) m2 m1 + (k1 + k12) 2 m2 2 + e -k2 m1-k1 m2-k12 (m1+m2)- (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) k2) m2 m1+(k1+k12) 2 m2 2 t 2 m1 m2 -(k12 + k2) m1 + k1 m2 + k12 m2 + (k12 + k2) 2 m1 2-2 (k12 (k2 - k12) + k1 (k12 + k2)) m2 m1 + (k1 + k12) 2 m2 2 + -k2 m1-k1 m2-k12 (m1+m2)- (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k1+k12) k2) m2 m1+(k1+k12) 2 m2 2 +2 -k2 m1-k1 m2-k12 (m1+m2)+ (k12+k2) 2 m1 2-2 ((k1-k12) k12+(k e 2 m1 m2 -(k12 + k2) m1 + k1 m2 + k12 m2 + (k12 + k2) 2 m1 2-2 (k12 (k2 - k12) + k1 (k12 + k2)) m2 m1 + (k1 + k12) 2 m2 2 4 k12 2 (m1 + m2) 2 + (k2 m1 - k1 m2) 2 + 2 k12 (m1 - m2) (k2 m1 - k1 m2)
wyklad6_2017_notes.nb 9 Dygresja In[12]:=? DSolve DSolve[eqn, u, x] solves a differential equation for the function u, with independent variable x. DSolve[eqn, u, {x, x min, x max }] solves a differential equation for x between x min and x max. DSolve[{eqn 1, eqn 2, }, {u 1, u 2, }, ] solves a list of differential equations. DSolve[eqn, u, {x 1, x 2, }] solves a partial differential equation. DSolve[eqn, u, {x 1, x 2, } Ω] solves the partial differential equation eqn over the region Ω. DSolve[eqn, u, {t, t min, t max }, {x 1, x 2, } Ω] solves the time-dependent partial differential equation eqn over the region Ω. DSolve działa na dwa sposoby: DSolve[row, y[t],t] zwraca jako wynik wyrażenie y[t], ale można również wykonać tą funkcję w składni: DSolve[row, y,t], wówczas jako wynik dostaniemy funkcję bez nazwy (czystą), ten drugi sposób jest nieco użyteczniejszy gdy np. rysujemy wynik w przestrzeni fazowej. In[11]:= roz =. roz = DSolve[{y''[t] - 3 y'[t] - 18 y[t] 0, y[0] 0, y'[0] == 0.1}, y[t], t] rozwiązywanie równań różniczkowych ParametricPlot[{y[t], y'[t]} /. %, {t, 0, 1}] wykres parametryczny Out[12]= y(t) 0.0111111 e -3 t 1. e 9 t - 1. 1.0 0.5 Out[13]= -1.0-0.5 0.5 1.0-0.5-1.0 Nie działa...!
10 wyklad6_2017_notes.nb In[14]:= {y[t], y'[t]} /. roz Out[14]= 0.0111111 e -3 t -1. + 1. e 9 t y (t) In[15]:= FullForm[y'[t]] pełna forma Out[15]//FullForm= Derivative[1][y][t] Derivative działa na funkcjach bez nazwy, zatem In[16]:= DSolve[{y''[t] - 3 y'[t] - 18 y[t] 0, y[0] 0, y'[0] == 0.1}, y, t] rozwiązywanie równań różniczkowych ParametricPlot[{y[t], y'[t]} /. %, {t, 0, 1}] wykres parametryczny Out[16]= y {t} 0.0111111 e -3 t 1. e 9 t - 1. 25 20 15 Out[17]= 10 5 1 2 3 4
wyklad6_2017_notes.nb 11 Powracamy do problemu fizycznego In[18]:= Clear[x1, x2] wyczyść m1 x1''[t] + k1 x1[t] + k12 x1[t] - x2[t] == 0, m2 x2''[t] + k2 x2[t] + k12 x2[t] - x1[t] == 0, x1[0] == 0, x2[0] == a, x1'[0] == 0, x2'[0] == 0 /. {k1 k, k2 k, k12 k, m1 M, m2 M} FullSimplify[% /. k M ω^2] uprość pełniej DSolve[%, {x1, x2}, t]; rozwiązywanie równań różniczkowych FullSimplify @@ {%, {k > 0, a > 0}}; uprość pełniej roz =. roz = Flatten@ FullSimplify[%%, Assumptions {ω > 0}] spłaszcz uprość pełniej założenia Out[19]= {k (x1(t) - x2(t)) + k x1(t) + M x1 (t) 0, k (x2(t) - x1(t)) + k x2(t) + M x2 (t) 0, x1(0) 0, x2(0) a, x1 (0) 0, x2 (0) 0} Out[20]= M x1 (t) + 2 ω 2 x1(t) M ω 2 x2(t), M ω 2 (x1(t) - 2 x2(t)) M x2 (t), x1(0) 0, a x2(0), x1 (0) 0, x2 (0) 0 Out[24]= x1 {t} - 1 4 a e-i 3 t ω-i t ω e i t ω - e i 3 t ω - e i 3 t ω+2 i t ω + e 2 i 3 t ω+i t ω, x2 {t} 1 4 a e-i 3 t ω-i t ω e i t ω + e i 3 t ω + e i 3 t ω+2 i t ω + e 2 i 3 t ω+i t ω In[25]:= {x1[t], x2[t]} /. roz Out[25]= - 1 4 a e-i 3 t ω-i t ω e i t ω - e i 3 t ω - e i 3 t ω+2 i t ω + e 2 i 3 t ω+i t ω, 1 4 a e-i 3 t ω-i t ω e i t ω + e i 3 t ω + e i 3 t ω+2 i t ω + e 2 i 3 t ω+i t ω In[26]:= {x1[t], x2[t]} /. roz /. ω 1 Out[26]= - 1 4 a e-i 3 t-i t e i t - e i 3 t - e i 3 t+2 i t + e 2 i 3 t+i t, 1 4 a e-i 3 t-i t e i t + e i 3 t + e i 3 t+2 i t + e 2 i 3 t+i t
12 wyklad6_2017_notes.nb In[27]:= rysunek1 =. rysunek1 = Plot Evaluate {x1[t], x2[t]} /. roz /. {ω 1, a 1}, wyk oblicz {t, 0, 10}, PlotStyle {{ Blue, Dotted}, { Red, Dashed}}, styl grafiki niebi wykropko cz linia przerywana AxesLabel {"t", "x(t)"}, oznaczenia osi ImageSize rozmiar obrazu Large duży x(t) 1.0 0.5 Out[28]= 2 4 6 8 10 t -0.5-1.0 In[29]:= rozbis = roz /. {a 1, ω 1} Out[29]= x1 {t} - 1 4 e-i 3 t-i t e i t - e i 3 t - e i 3 t+2 i t + e 2 i 3 t+i t, x2 {t} 1 4 e-i 3 t-i t e i t + e i 3 t + e i 3 t+2 i t + e 2 i 3 t+i t
wyklad6_2017_notes.nb 13 In[30]:= Manipulate[ zmieniaj Plot[ Evaluate[{x1[t], x2[t]} /. rozbis], {t, 0, T}, wyk oblicz PlotRange {{0, 100}, {-1, 1}}, zakres wykresu PlotStyle { Red, styl grafiki cz Thick}], {T, 0.001, 100}] gruby T 1.0 0.5 Out[30]= 20 40 60 80 100-0.5-1.0 Alternatywnie In[31]:= % /. Manipulate Animate zmieniaj animuj T 1.0 0.5 Out[31]= 20 40 60 80 100-0.5-1.0
14 wyklad6_2017_notes.nb In[32]:= Animate[ animuj Plot[ Evaluate[{x1[t], x2[t]} /. rozbis], {t, 0, T}, wyk oblicz PlotRange {{0, 50}, {-1, 1}}, zakres wykresu PlotStyle { Red, styl grafiki cz Thick}], {T, 0.001, 100}] gruby T 1.0 0.5 Out[32]= 10 20 30 40 50-0.5-1.0 oraz In[33]:= Table[ tabela Plot[ Evaluate[{x1[t], x2[t]} /. rozbis], {t, 0, T}, wyk oblicz PlotRange {{0, 20}, {-1, 1}}, zakres wykresu ListAnimate[ animuj liste %] PlotStyle { Red, styl grafiki cz Thick}], {T, 0.001, 20, 0.1}]; gruby 1.0 0.5 Out[34]= 5 10 15 20-0.5-1.0
wyklad6_2017_notes.nb 15 Przestrzeń fazowa In[35]:= Manipulate[ zmieniaj ParametricPlot[ Evaluate[{{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. rozbis], {t, 0, T}, wykres parametry oblicz PlotRange {{-2, 2}, {-2, 2}}, zakres wykresu MaxRecursion 10], maksymalny poziom rekurencji {T, 0.001, 100}] PlotStyle {{ Red, Dashed}, { Blue, Dotted}}, styl grafiki cz linia przer niebi wykropkowany T 2 1 Out[35]= -2-1 1 2-1 -2
16 wyklad6_2017_notes.nb In[36]:= Options[ ParametricPlot] opcje wykres parametryczny Out[36]= {AlignmentPoint Center, AspectRatio Automatic, Axes True, AxesLabel None, AxesOrigin Automatic, AxesStyle {}, Background None, BaselinePosition Automatic, BaseStyle {}, BoundaryStyle Automatic, ColorFunction Automatic, ColorFunctionScaling True, ColorOutput Automatic, ContentSelectable Automatic, CoordinatesToolOptions Automatic, DisplayFunction $DisplayFunction, Epilog {}, Evaluated Automatic, EvaluationMonitor None, Exclusions Automatic, ExclusionsStyle None, FormatType TraditionalForm, Frame Automatic, FrameLabel None, FrameStyle {}, FrameTicks Automatic, FrameTicksStyle {}, GridLines None, GridLinesStyle {}, ImageMargins 0., ImagePadding All, ImageSize Automatic, ImageSizeRaw Automatic, LabelStyle {}, MaxRecursion Automatic, Mesh Automatic, MeshFunctions Automatic, MeshShading None, MeshStyle Automatic, Method Automatic, PerformanceGoal $PerformanceGoal, PlotLabel None, PlotLegends None, PlotPoints Automatic, PlotRange Automatic, PlotRangeClipping True, PlotRangePadding Automatic, PlotRegion Automatic, PlotStyle Automatic, PlotTheme $PlotTheme, PreserveImageOptions Automatic, Prolog {}, RegionFunction (True &), RotateLabel True, TargetUnits Automatic, TextureCoordinateFunction Automatic, TextureCoordinateScaling Automatic, Ticks Automatic, TicksStyle {}, WorkingPrecision MachinePrecision} In[37]:=? roz Global`roz roz = x1 Function {t}, - 1 4 a e-i t ω-i 3 t ω e i t ω - e i 3 t ω - e 2 i t ω+i 3 t ω + e i t ω+2 i 3 t ω, x2 Function {t}, 1 4 a e-i t ω-i 3 t ω e i t ω + e i 3 t ω + e 2 i t ω+i 3 t ω + e i t ω+2 i 3 t ω In[38]:= roz /. ω 1 Out[38]= x1 {t} - 1 4 a e-i 3 t-i t e i t - e i 3 t - e i 3 t+2 i t + e 2 i 3 t+i t, x2 {t} 1 4 a e-i 3 t-i t e i t + e i 3 t + e i 3 t+2 i t + e 2 i 3 t+i t In[39]:= Evaluate {{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. roz /. ω 1 oblicz Out[39]= - 1 4 a e-i 3 t-i t e i t - e i 3 t - e i 3 t+2 i t + e 2 i 3 t+i t - 1 4 -i - i 3 a e-i 3 t-i t e i t - e i 3 t - e i 3 t+2 i t + e 2 1 4 a e-i 3 t-i t e i t + e i 3 t + e i 3 t+2 i t + e 2 i 3 t+i t 1 4 -i - i 3 a e-i 3 t-i t e i t + e i 3 t + e i 3 t+2 i t + e 2
wyklad6_2017_notes.nb 17 In[40]:= Manipulate zmieniaj ParametricPlot wykres parametryczny Evaluate {{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. roz /. a A /. ω Ω, oblicz {t, 0, 10}, MaxRecursion 10, maksymalny poziom rekurencji PlotRange {{-2, 2}, {-2, 2}}, zakres wykresu {Ω, 0.001, 2, 0.1}, {A, 0, 1, 0.1} PlotStyle {{ Red}, { Blue}}, styl grafiki czerw niebieski Ω A 2 1 Out[40]= -2-1 1 2-1 -2 NDSolve oraz opór powietrza Wprowadźmy opór powietrza, m=1, k=1
18 wyklad6_2017_notes.nb In[41]:= rownania =. row1 =. row1 = x1''[t] + x1[t] + x1[t] - x2[t] + b x1'[t] row2 = x2''[t] + x2[t] + x2[t] - x1[t] + b x2'[t] rownania = { row1 == 0, row2 == 0, x1[0] == 0, x2[0] 1, x1'[0] == 0, x2'[0] == 0} Out[43]= b x1 (t) + x1 (t) + 2 x1(t) - x2(t) Out[44]= b x2 (t) - x1(t) + x2 (t) + 2 x2(t) Out[45]= {b x1 (t) + x1 (t) + 2 x1(t) - x2(t) 0, b x2 (t) - x1(t) + x2 (t) + 2 x2(t) 0, x1(0) 0, x2(0) 1, x1 (0) 0, x2 (0) 0} In[46]:=? NDSolve NDSolve[eqns, u, {x, x min, x max }] finds a numerical solution to the ordinary differential equations eqns for the function u with the independent variable x in the range x min to x max. NDSolve[eqns, u, {x, x min, x max }, {y, y min, y max }] solves the partial differential equations eqns over a rectangular region. NDSolve[eqns, u, {x, y} Ω] solves the partial differential equations eqns over the region Ω. NDSolve[eqns, u, {t, t min, t max }, {x, y} Ω] solves the time-dependent partial differential equations eqns over the region Ω. NDSolve[eqns, {u 1, u 2, }, ] solves for the functions u i. In[47]:= Rozwiazanie[op_] := Flatten@ NDSolve[rownania /. b op, {x1, x2}, {t, 0, 100}] spłaszcz rozwiąż numerycznie równanie różniczkowe In[48]:= RozwiazanieScisle[op_] := Flatten@ DSolve[rownania /. b op, {x1, x2}, {t, 0, 100}] spłaszcz rozwiązywanie równań różniczkowych In[49]:= Rozwiazanie[0.1] Out[49]= x1 InterpolatingFunction Domain: ( 0. 100. ) Output: scalar, x2 InterpolatingFunction Domain: ( 0. 100. ) Output: scalar
wyklad6_2017_notes.nb 19 In[50]:= rysunek2 =. rysunek2 = Plot[ Evaluate[{x1[t], x2[t]} /. Rozwiazanie[0.2]], {t, 0, 10}, wyk oblicz PlotStyle {{ Blue}, { Red}}, styl grafiki niebieski czerw AxesLabel {"t", "x(t)"}, oznaczenia osi ImageSize rozmiar obrazu Large] duży x(t) 1.0 0.5 Out[51]= 2 4 6 8 10 t -0.5
20 wyklad6_2017_notes.nb In[52]:= rysunek2scisle =. rysunek2scisle = Plot[ Evaluate[{x1[t], x2[t]} /. RozwiazanieScisle[0.2]], wyk oblicz {t, 0, 10}, PlotStyle {{ Black, Dashed, Thick}, { Black, styl grafiki czarny linia prz gruby czarny AxesLabel {"t", "x(t)"}, oznaczenia osi ImageSize rozmiar obrazu Large] duży Dotted, wykrop Thick}}, gruby x(t) 1.0 0.5 Out[53]= 2 4 6 8 10 t -0.5
wyklad6_2017_notes.nb 21 In[54]:= Show[rysunek2, rysunek2scisle, rysunek1] pokaż (* UWAGA zwróć uwagę na kolejność wkładanych rysunków do Show*) pokaż x(t) 1.0 0.5 Out[54]= 2 4 6 8 10 t -0.5 In[55]:= rysunek3 =. rysunek3[b_] := Plot[ Evaluate[{x1[t], x2[t]} /. Rozwiazanie[b]], wyk oblicz {t, 0, 100}, PlotStyle {{ Blue}, { Red}}, AxesLabel {"t", "x(t)"}, styl grafiki niebieski czerw oznaczenia osi ImageSize Large, rozmiar obrazu duży ] PlotRange {{0, 10}, {-2, 2}} zakres wykresu
22 wyklad6_2017_notes.nb In[57]:= Manipulate[ Show[rysunek3[b], rysunek1], {b, - 0.3, 0.3, 0.001}] zmieniaj pokaż b x(t) 2 1 Out[57]= 0 2 4 6 8 10 t -1-2 Sprawdźmy jak się ma rozwiązanie ścisłe do numerycznego
wyklad6_2017_notes.nb 23 In[58]:= Show[ pokaż Plot[ Evaluate[{x1[t], x2[t]} /. Rozwiazanie[0.2]], wyk oblicz {t, 0, #}, PlotStyle {{ Blue}, { Red}}, AxesLabel {"t", "x(t)"}, styl grafiki niebieski czerw oznaczenia osi ImageSize rozmiar obrazu Large, duży PlotRange {{0, #}, {-4, 4}}], zakres wykresu Plot[ Evaluate[{x1[t], x2[t]} /. RozwiazanieScisle[0.2]], {t, 0, #}, PlotStyle wyk oblicz styl grafiki ] &[ 10] {{ Blue, Dotted}, { Red, niebi wykropko cz Dotted}}, wykropko AxesLabel {"t", "x(t)"}, oznaczenia osi ImageSize rozmiar obrazu Large] duży x(t) 4 2 Out[58]= 0 2 4 6 8 10 t -2-4 In[59]:= Plot Evaluate {row1, row2} /. b # /. Rozwiazanie[#], wyk oblicz {t, 0, 100}, PlotRange {{0, 100}, {-0.00001, 0.00001}} &[0.2] zakres wykresu 0.00001 5. 10-6 Out[59]= 20 40 60 80 100-5. 10-6 -0.00001
24 wyklad6_2017_notes.nb Użyjmy funkcji bez nazwy In[60]:= Manipulate zmieniaj Plot Evaluate {row1, row2} /. b # /. Rozwiazanie[#], {t, 0, 100}, wyk oblicz PlotRange {{0, 100}, {-0.00001, 0.00001}} &[c], zakres wykresu {c, -0.5, 0.5, 0.01} c 0.00001 5. 10-6 Out[60]= 20 40 60 80 100-5. 10-6 -0.00001 Kolejna wariacja
wyklad6_2017_notes.nb 25 In[61]:= Manipulate zmieniaj Plot Evaluate {row1, row2} /. b #1 /. Rozwiazanie[#1], {t, 0, #2}, wyk oblicz PlotRange {{0, #2}, {-0.00001, 0.00001}} &[c, d], zakres wykresu {c, -0.5, 0.5, 0.01}, {d, 10, 100, 10} c d 0.00001 Out[61]= 5. 10-6 10 20 30 40 50 60-5. 10-6 -0.00001 Kolejna wariacja
26 wyklad6_2017_notes.nb In[62]:= Manipulate zmieniaj Plot Evaluate {row1, row2} /. b #1 /. Rozwiazanie[#1], {t, 0, #2}, wyk oblicz PlotRange {{0, #2}, {-#3, #3}} &[c, d, e], zakres wykresu {c, -0.5, 0.5, 0.01}, {d, 10, 100, 10}, {e, {0.00001, 0.0001, 0.001, 1}} c d e 0.00001 0.0001 0.001 1 0.00001 Out[62]= 5. 10-6 2 4 6 8 10-5. 10-6 -0.00001
wyklad6_2017_notes.nb 27 In[63]:= Manipulate zmieniaj ParametricPlot Evaluate {row1, row2} /. b # /. Rozwiazanie[#], {t, 0, 100}, wykres parametry oblicz PlotRange {{-0.00001, 0.00001}, {-0.00001, 0.00001}} &[c], zakres wykresu {c, -0.5, 0.5, 0.01} c 0.00001 5. 10-6 Out[63]= -0.00001-5. 10-6 5. 10-6 0.00001-5. 10-6 -0.00001 Rozwiązanie w przestrzeni fazowej
28 wyklad6_2017_notes.nb In[64]:= Manipulate[ zmieniaj ParametricPlot[ wykres parametryczny Evaluate[{{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. RozwiazanieScisle[b] oblicz ], {t, 0, T}, MaxRecursion 10], maksymalny poziom rekurencji PlotRange {{-1, 1}, {-1, 1}}, zakres wykresu {T, 0.001, 100, 0.1}, {b, 0, 0.5}] PlotStyle {{ Red}, { Blue}}, styl grafiki czerw niebieski T b 1.0 0.5 Out[64]= -1.0-0.5 0.5 1.0-0.5-1.0 NIewiele widać, więc rysujmy tylko ślad: od (t-epsilon,t)
wyklad6_2017_notes.nb 29 In[65]:= Manipulate[ zmieniaj ParametricPlot[ wykres parametryczny Evaluate[{{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. RozwiazanieScisle[b] oblicz ], {t, 0.93 T, T}, MaxRecursion 10], maksymalny poziom rekurencji {T, 0.001, 60, 0.03}, {b, 0, 0.5}] PlotRange {{-1, 1}, {-1, 1}}, zakres wykresu PlotStyle {{ Red}, { Blue}}, styl grafiki czerw niebieski T b 1.0 0.5 Out[65]= -1.0-0.5 0.5 1.0-0.5-1.0 Dodajmy punkt In[66]:=? Point Point[p] is a graphics and geometry primitive that represents a point at p. Point[{p 1, p 2, }] represents a collection of points.
30 wyklad6_2017_notes.nb In[67]:= Graphics[{ Red, Point[{0, 0}]}] grafika cz punkt Out[67]= In[69]:= Manipulate[ zmieniaj Show[ pokaż ParametricPlot[ wykres parametryczny Evaluate[{{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. RozwiazanieScisle[b] oblicz ], {t, 0.93 T, T}, PlotStyle {{ Red}, { Blue}}, styl grafiki czerw niebieski MaxRecursion 10 maksymalny poziom rekurencji ], Graphics[ grafika PlotRange {{-1.1, 1.1}, {-1.1, 1.1}}, zakres wykresu { Red, PointSize[ Large], Point[ Evaluate[{x1[T], x1'[t]} /. #]], cz rozmiar kro duży punkt oblicz Blue, niebi PointSize[ Large], Point[ Evaluate[{x2[T], x2'[t]} /. #]] rozmiar kro duży punkt oblicz } ] &[RozwiazanieScisle[b]] ], {T, 0.001, 60, 0.03}, {b, 0, 0.5}]
wyklad6_2017_notes.nb 31 T b 1.0 0.5 Out[69]= -1.0-0.5 0.5 1.0-0.5-1.0 Gotowa animacja
32 wyklad6_2017_notes.nb In[71]:= tabel =. tabela = Table[ tabela Show[ pokaż ParametricPlot[ wykres parametryczny Evaluate[{{x1[t], x1'[t]}, {x2[t], x2'[t]}} /. RozwiazanieScisle[#] oblicz ], {t, 0.93 T, T}, PlotStyle {{ Red}, { Blue}}, styl grafiki czerw niebieski MaxRecursion 10, maksymalny poziom r Ticks znaczki Graphics[ grafika None], żaden PlotRange {{-1.5, 1.5}, {-1.5, 1.5}}, zakres wykresu PlotLabel "b=" <> ToString[#], etykieta grafiki przemień na ciąg znaków { Red, PointSize[ Large], Point[ Evaluate[{x1[T], x1'[t]} /. #]], cz rozmiar kro duży punkt oblicz Blue, niebi PointSize[ Large], Point[ Evaluate[{x2[T], x2'[t]} /. #]] rozmiar kro duży punkt oblicz } ] &[RozwiazanieScisle[#]] ], {T, 0.001, 20, 0.1}] & /@ {0, 0.1, 0.2}; GraphicsRow[#, Frame All, ImageSize Large] & /@ Transpose[%]; rząd z grafikami ramka ws rozmiar obrazu duży transpozycja Out[72]= $Aborted ListAnimate[%] animuj liste Export["oscylacje.avi", %] eksportuj In[70]:=? Export Export[" file.ext", expr] exports data to a file, converting it to the format corresponding to the file extension ext. Export[ file, expr, " format"] exports data in the specified format. Export[ file, exprs, elems] exports data by treating exprs as elements specified by elems. In[71]:= f /@ Transpose[{{a, b, c}, {x, y, z}}] transpozycja Out[71]= {f ({a, x}), f ({b, y}), f ({c, z})}
wyklad6_2017_notes.nb 33 In[72]:=? GraphicsRow GraphicsRow[{g 1, g 2, }] generates a graphic in which the g i are laid out in a row. GraphicsRow[list, spacing] leaves the specified spacing between successive elements. In[73]:= GraphicsRow[{ Plot[x, {x, 0, 1}], Plot[x^3, {x, 0, 1}]}] rząd z grafikami wykres wykres Out[73]= 1.0 0.8 0.6 0.4 0.2 1.0 0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8 1.0 0.2 0.4 0.6 0.8 1.0 In[74]:= StringJoin["b=", ToString[#]] &[1] połącz ciągi znaków przemień na ciąg znaków Out[74]= b=1 Równoważnie: In[75]:= "b=" <> ToString[1] przemień na ciąg Out[75]= b=1