Example 2 (second order) The section 4.5.6 studies the second order equation mu"(t) + k u(t) +kquº(t) = 0 which models s
Posted: Fri Apr 29, 2022 11:33 am
Example 2 (second order) The section 4.5.6 studies the second order equation mu"(t) + k u(t) +kquº(t) = 0 which models so called hard spring with no damping. The parameters are the mass m, and two non-negative spring constants ki and k2. In addition to these three parameters, there will be two initial conditions (0) = up and u'(0) = vo. To study the solutions of such equation, we want to find the characteristic scales oft and u. There are infinitely many choices, but a reasonable choice seems to be m tra and uc = UD. k Let's choose some values of the parameters, solve the equation and plot the solution. There is not really any good choice of the parameters, so let's just choose some nice numbers: • m=4 . k = 9 k2 = 5 • U=1 • U = 0 Thente = 4/9 = 2/3, so we will find the solution on the interval (0,4), that is 6 times the te, it should show us enough if the behavior of the solution. We will let u range from - 1.5 to 1.5. Solving the equation We want to solve the IVP 44" +9u + 5 = 0.4(0) = 1, U'(0) = 0. This is a second order problem, so in order to solve it numerically, we will need to turn it into a first order system. We will introduce a new variable v which will be the derivarive of u, so v = u' and " = v'. Then the IVP becomes u=u 5 9 = -U- 4 u(0) = 1 v(0) = 0 Let's use the the 4th order Runge-Kutta method to solve this sytem:
Let's use the the 4th order Runge-Kutta method to solve this sytem: %var u, V, t 3 4 pts=desolve_system_rk4([v, -9/4*u - 5/5*u^3], [u, v], ics=(0,1,2), ivar=t, step=0.1, end_points=6) pts [(0, 1, ), (0.1, 0.9838207645658366, -0.3221759652913411], [0.2, 0.9361145984615182,-0.627965517122941], [0.3, 0.8592437682954274, -6.9034837138799486), (0.4, 0.7567572817558581, -1.139071474798703], [0.5, 0.6329320957372736, -1.32981077940511], [0.6000000000000001, 0.4923232068967692, -1.474874312166993], [0.7000000000000001, 0.3394218414806781, -1.576112703838245], [0.8, 0.1784663529841505, -1.6364009032868], [0.9, 0.01342354863942333, -1.658183044878126], (1.0, -0.1519225528467996, -1.64249205292915], [1.1, -0.3138015883994654, -1.588575496085854), (1.2, -0.4682872960352044, -1.494166167149636), (1.3, -0.6111856308623556, -1.356370214849613], [1.4, -0.7380383738730678, -1.173059787505673), (1.5, -0.84428152374038, -0.9445203542139876), [1.6, -6.925564444981963, -0.6749375141863101], [1.7, -0.9781879995689888, -0.373204248748203], [1.8, -0.999578042241927, -0.0526093097990149], [1.9, -0.9886170708795922, 0.270708684337052], [2.0, -0.9458925941051362, 0.5801837327417534], [2.1, -0.8735295489369227, 0.8613809836420735], [2.2, -0.7749143988754268, 1.103888563584481], [2.3, -0.6542383559211605, 1.302037866539427], [2.4, -0.5160383071585988, 1.45442130489247], [2.5, -0.364832845358645, 1.562567786534133], [2.6, -0.2049064174020676, 1.629294511211209], [2.7, -0.6402666371936424, 1.657196533673022], [2.8, 0.1252835663301749, 1.647577413801586], [2.9, 0.2879837117037602, 1.599972414996816), (3.0, 0.4439426748223394, 1.512314811332618], [3.1, 0.5890131895941946, 1.381728873624468], [3.2, 0.7187734539653792, 1.205853524350364], [3.3, 0.8286589725253295, 0.984472338173402], [3.4, 0.9142571287067607, 0.7210684084729899], [3.5, 0.971731063585041, 0.4237364656140645], [3.6, 0.9982885953270895, 0.1051515372457613], [3.7, 0.9925773819943488, -0.2188685319312217], [3.8, 0.9548917237972144, -0.5316467478999706], [3.9, 0.8871267080192661, -8.8182490363038837], [4.0, 0.7924941963673342, -1.067529591813761], [4.100000000000001, 0.6750873787250062, -1.273055672891946], [4.2, 0.5394153400116666, -1.432803467482068], [4.3, 0.3900176695223738, -1.547935906101839], [4.4, 0.2312260534034507, -1.621172179005989], [4.5, 0.06708873202699919, -1.655229926071135], [4.600000000000001, -0.09856736956689455, -1.651670762880196], [4.7, -0.261986954288626, -1.610322061180547], [4.800000000000001, -0.4193106197729253, -1.529338573678146], [4.9, -0.5664373035024534, -1.405897866830171], [5.0, -0.6989850486216485, -1.237449198845927], [5.100000000000001, -0.8123966585799943, -1.023315908554328], [5.2, -0.9022088290203195, -0.7662885653266809], [5.300000000000001, -0.9644595288658276, -0.473709110928186], [5.4, -6.9961571418680224, -0.1575545878923204], [5.5, -0.9956960320569292, 0.1667244709733608], [5.600000000000001, -0.963100031237674, 0.4824099627639254], [5.7, -0.9000187100596093, 0.7741234757501112], [5.800000000000001, -0.8994776187892504, 1.630009679826624], [5.9, -0.6954594646175976, 1.24286292409962], [6.0, -0.562435274198956, 1.418089989576164]] Note that unlike the desolve_rk4 function, the desolve_system_rk4 does not accept an output parameter, so we can not specify that want we want the plot rather than a list of points. That's because for a sustem, the solution is not a list of points, but a list of multidimensional vectors, so there is no good way to plot them. If you look at the result we got from the desolve_system_rk4 above, you see that it is a list of vectors, where each vector contains three numbers: 1. the value of t 2. the value of u 3. the value of v In this case we are not actually interested in the values of u, since it was just a new variable that we introduced to turn the second order equation to a first order system, so we will drop the v values. We will then be able to plot the resulting points (t, u):
in pts] sol = [[time, pos] for time, pos, p = list_plot(sol, plotjoined=True) show(p, ymin=-1.5, ymax = 1.5) 1.5 1.0 0.5 2 3 A 4 5 6 -0.5 -1.0 -1.5
An interactive plot We can now create an interactive plot that will show the solution of the hard spring problem and the solution of the corresponding regular spring for comparison. We will include sliders for all three parameters m, k and k2, as well as for the two initial conditions: m 1.452400eeeee000 k1 4.99060000000001 k2 1.284000000000001 uo 1.0000000000000024 vo 3.4416913763379853e-15 2 1 3 -1 -2
You can experiment with the sliders to see how the values of the parameters affect the solution. When you are done with that, your actual task in this extra credit part is as follows: Your task: Find the nondimensionalized version of the equation, with a single parameter e. Then create an interactive plot for the nondimensionalized equation, with three sliders, one for e, and one for each of the two initial conditions. Use the method described and used above to find the solution of the second order equation. It is probably a good idea to cut and paste the code from above and edit it for the 3 slide nondimensionalized version. Make sure you have good ranges for all the sliders. Experiment!
Let's use the the 4th order Runge-Kutta method to solve this sytem: %var u, V, t 3 4 pts=desolve_system_rk4([v, -9/4*u - 5/5*u^3], [u, v], ics=(0,1,2), ivar=t, step=0.1, end_points=6) pts [(0, 1, ), (0.1, 0.9838207645658366, -0.3221759652913411], [0.2, 0.9361145984615182,-0.627965517122941], [0.3, 0.8592437682954274, -6.9034837138799486), (0.4, 0.7567572817558581, -1.139071474798703], [0.5, 0.6329320957372736, -1.32981077940511], [0.6000000000000001, 0.4923232068967692, -1.474874312166993], [0.7000000000000001, 0.3394218414806781, -1.576112703838245], [0.8, 0.1784663529841505, -1.6364009032868], [0.9, 0.01342354863942333, -1.658183044878126], (1.0, -0.1519225528467996, -1.64249205292915], [1.1, -0.3138015883994654, -1.588575496085854), (1.2, -0.4682872960352044, -1.494166167149636), (1.3, -0.6111856308623556, -1.356370214849613], [1.4, -0.7380383738730678, -1.173059787505673), (1.5, -0.84428152374038, -0.9445203542139876), [1.6, -6.925564444981963, -0.6749375141863101], [1.7, -0.9781879995689888, -0.373204248748203], [1.8, -0.999578042241927, -0.0526093097990149], [1.9, -0.9886170708795922, 0.270708684337052], [2.0, -0.9458925941051362, 0.5801837327417534], [2.1, -0.8735295489369227, 0.8613809836420735], [2.2, -0.7749143988754268, 1.103888563584481], [2.3, -0.6542383559211605, 1.302037866539427], [2.4, -0.5160383071585988, 1.45442130489247], [2.5, -0.364832845358645, 1.562567786534133], [2.6, -0.2049064174020676, 1.629294511211209], [2.7, -0.6402666371936424, 1.657196533673022], [2.8, 0.1252835663301749, 1.647577413801586], [2.9, 0.2879837117037602, 1.599972414996816), (3.0, 0.4439426748223394, 1.512314811332618], [3.1, 0.5890131895941946, 1.381728873624468], [3.2, 0.7187734539653792, 1.205853524350364], [3.3, 0.8286589725253295, 0.984472338173402], [3.4, 0.9142571287067607, 0.7210684084729899], [3.5, 0.971731063585041, 0.4237364656140645], [3.6, 0.9982885953270895, 0.1051515372457613], [3.7, 0.9925773819943488, -0.2188685319312217], [3.8, 0.9548917237972144, -0.5316467478999706], [3.9, 0.8871267080192661, -8.8182490363038837], [4.0, 0.7924941963673342, -1.067529591813761], [4.100000000000001, 0.6750873787250062, -1.273055672891946], [4.2, 0.5394153400116666, -1.432803467482068], [4.3, 0.3900176695223738, -1.547935906101839], [4.4, 0.2312260534034507, -1.621172179005989], [4.5, 0.06708873202699919, -1.655229926071135], [4.600000000000001, -0.09856736956689455, -1.651670762880196], [4.7, -0.261986954288626, -1.610322061180547], [4.800000000000001, -0.4193106197729253, -1.529338573678146], [4.9, -0.5664373035024534, -1.405897866830171], [5.0, -0.6989850486216485, -1.237449198845927], [5.100000000000001, -0.8123966585799943, -1.023315908554328], [5.2, -0.9022088290203195, -0.7662885653266809], [5.300000000000001, -0.9644595288658276, -0.473709110928186], [5.4, -6.9961571418680224, -0.1575545878923204], [5.5, -0.9956960320569292, 0.1667244709733608], [5.600000000000001, -0.963100031237674, 0.4824099627639254], [5.7, -0.9000187100596093, 0.7741234757501112], [5.800000000000001, -0.8994776187892504, 1.630009679826624], [5.9, -0.6954594646175976, 1.24286292409962], [6.0, -0.562435274198956, 1.418089989576164]] Note that unlike the desolve_rk4 function, the desolve_system_rk4 does not accept an output parameter, so we can not specify that want we want the plot rather than a list of points. That's because for a sustem, the solution is not a list of points, but a list of multidimensional vectors, so there is no good way to plot them. If you look at the result we got from the desolve_system_rk4 above, you see that it is a list of vectors, where each vector contains three numbers: 1. the value of t 2. the value of u 3. the value of v In this case we are not actually interested in the values of u, since it was just a new variable that we introduced to turn the second order equation to a first order system, so we will drop the v values. We will then be able to plot the resulting points (t, u):
in pts] sol = [[time, pos] for time, pos, p = list_plot(sol, plotjoined=True) show(p, ymin=-1.5, ymax = 1.5) 1.5 1.0 0.5 2 3 A 4 5 6 -0.5 -1.0 -1.5
An interactive plot We can now create an interactive plot that will show the solution of the hard spring problem and the solution of the corresponding regular spring for comparison. We will include sliders for all three parameters m, k and k2, as well as for the two initial conditions: m 1.452400eeeee000 k1 4.99060000000001 k2 1.284000000000001 uo 1.0000000000000024 vo 3.4416913763379853e-15 2 1 3 -1 -2
You can experiment with the sliders to see how the values of the parameters affect the solution. When you are done with that, your actual task in this extra credit part is as follows: Your task: Find the nondimensionalized version of the equation, with a single parameter e. Then create an interactive plot for the nondimensionalized equation, with three sliders, one for e, and one for each of the two initial conditions. Use the method described and used above to find the solution of the second order equation. It is probably a good idea to cut and paste the code from above and edit it for the 3 slide nondimensionalized version. Make sure you have good ranges for all the sliders. Experiment!