352 - Topic 19 - Numerical Solutions for Systems

30 days ago by Professor352

John Travis

Mississippi College

First we consider Euler's Method for Systems.  This is the kind of method one can do relatively easy by hand and which is good for demonstration purposes.  However, practically one would want to utilize numerical methods which yield greater accuracy.  The cost is more calculations...not easily done by hand but no problem for a computer.

# Euler's method for systems # Code below written perhaps inefficiently but to show # how the solution points are generated t,x,y = var('t,x,y') numpts = 5 # de1(x,y) = y+y^2 # de2(x,y) = -x+y/5-x*y+6*y^2/5 # de1(x,y) = y # de2(x,y) = -2*x-y/2 de1 = 2*x + y de2 = -1*x+y delt = 1/4 old_x = 1/2 old_y = 1/2 soln_x = [old_x] soln_y = [old_y] for t in range(1,numpts): new_x = old_x+delt*de1(x=old_x,y=old_y) new_y = old_y+delt*de2(x=old_x,y=old_y) soln_x.append(new_x) soln_y.append(new_y) old_x = new_x old_y = new_y m = len(soln_x) pts = [] for k in range(m): point = [soln_x[k],soln_y[k]] print point pts.append(point) # G = points(pts)+plot_vector_field((de1(x,y), de2(x,y)), (x,-1/2,2), (y,-1,1)) G = points(pts) G.show() 
       
[1/2, 1/2]
[7/8, 1/2]
[23/16, 13/32]
[289/128, 19/128]
[1753/512, -97/256]
[1/2, 1/2]
[7/8, 1/2]
[23/16, 13/32]
[289/128, 19/128]
[1753/512, -97/256]
# Euler's method for systems # Code below written perhaps inefficiently but to show # how the solution points are generated var('t,x,y') de1(x,y) = y+y^2 de2(x,y) = -x+y/5-x*y+6*y^2/5 # from the inside spiraling out delt = 0.05 old_x = 1 old_y = 1 soln_x = [old_x] soln_y = [old_y] for t in range(1,1000): new_x = old_x+delt*de1(old_x,old_y) new_y = old_y+delt*de2(old_x,old_y) soln_x.append(new_x) soln_y.append(new_y) old_x = new_x old_y = new_y m = len(soln_x) pts1 = [] for k in range(m): point = [soln_x[k],soln_y[k]] print point pts1.append(point) G = points(pts1,color='red') # And from the outside spiraling in delt = 0.05 old_x = .01 old_y = .01 soln_x = [old_x] soln_y = [old_y] for t in range(1,1000): new_x = old_x+delt*de1(old_x,old_y) new_y = old_y+delt*de2(old_x,old_y) soln_x.append(new_x) soln_y.append(new_y) old_x = new_x old_y = new_y m = len(soln_x) pts1 = [] for k in range(m): point = [soln_x[k],soln_y[k]] print point pts1.append(point) G += points(pts1,color='blue') G +=plot_vector_field((de1(x,y), de2(x,y)), (x,-1/2,2), (y,-1,1), color='yellow') G.show() 
       
WARNING: Output truncated!  
full_output.txt



[1, 1]
[1.10000000000000, 0.970000000000000]
[1.19554500000000, 0.927804000000000]
[1.28497621312080, 0.873492434085960]
[1.36680028644537, 0.807637039708032]
[1.43979601782619, 0.731316124196504]
[1.50310298771150, 0.646081578788237]
[1.55627813697339, 0.553876172008416]
[1.59931088626975, 0.456908486860592]
[1.63259457888104, 0.357501013484366]
[1.65685997828737, 0.257932002325746]
[1.67308302429485, 0.160292197915408]
[1.68238231362625, 0.0663734762396137]
[1.68592125935563, -0.0224008565043855]
[1.68482630644902, -0.105002516124457]
[1.68012745706242, -0.180786774834114]
[1.67272231121846, -0.249452742744653]
[1.66336100762437, -0.310986527062072]
[1.65264731227197, -0.365597542362485]
[1.64105051330292, -0.413655999832889]
[1.62892327762117, -0.455636888781669]
[1.61652168190301, -0.492073246371459]
[1.60402482357417, -0.523519544550458]
[1.59155248202296, -0.550524701108833]
[1.57918011929407, -0.573613477705975]
[1.56695106649907, -0.593274723131762]
[1.55488607519783, -0.609954906854696]
[1.54299057927490, -0.624055540821019]
[1.53126006813532, -0.635933315089653]
[1.51968396144289, -0.645902016203175]
[1.50824833135949, -0.654235522830852]
[1.49693776118464, -0.661171365685823]
[1.48573657164049, -0.666914493718286]
[1.47462959405115, -0.671641008047884]
[1.46360262583334, -0.675501713857138]
[1.45264266841168, -0.678625404254129]
[1.44173802016393, -0.681121834454926]
[1.43087827610974, -0.683084374350523]
[1.42005427051631, -0.684592346550196]
[1.40925798723655, -0.685713068420138]
[1.39848245442565, -0.686503622802859]
[1.38772163449158, -0.687012384735411]
[1.37697031609380, -0.687280331827505]
[1.36622401222828, -0.687342164891376]
[1.35547886656558, -0.687227263538872]
[1.34473156897620, -0.686960499184740]
[1.33397928038897, -0.686562925484320]
[1.32321956664723, -0.686052363855670]
[1.31245034075205, -0.685443899489551]
[1.30166981274494, -0.684750301188629]
[1.29087644643440, -0.683982376522825]
[1.28006892217795, -0.683149272144667]
[1.26924610497231, -0.682258727669061]
[1.25840701716289, -0.681317290271664]
[1.24755081515046, -0.680330496081525]
[1.23667676954131, -0.679303023518040]
[1.22578424825345, -0.678238822931444]
[1.21487270215345, -0.677141226232379]
[1.20394165285500, -0.676013039623944]

...

[-0.242728623086857, 0.279575839340331]
[-0.224841698622698, 0.302590840811220]
[-0.205134095734994, 0.325754259098821]
[-0.183540590914002, 0.348976621984423]
[-0.160002525680198, 0.372153067482177]
[-0.134469977024270, 0.395161870316031]
[-0.106904238320885, 0.417863032476618]
[-0.0772806110015262, 0.440097012012530]
[-0.0455914914017819, 0.461683683781087]
[-0.0118497160192438, 0.482421647006140]
[0.0239078986060691, 0.502088015983098]
[0.0616169181949162, 0.520438850291384]
[0.101181690554116, 0.537210396794916]
[0.142471960915090, 0.552121324054085]
[0.185319924941556, 0.564876126252334]
[0.229517983154665, 0.575169853482453]
[0.274817493846539, 0.582694283243713]
[0.320928839394969, 0.587145579917330]
[0.367523114991659, 0.588233392191804]
[0.414235710785723, 0.585691213353486]
[0.460671981323371, 0.579287680988482]
[0.506415076240046, 0.568838331585039]
[0.551035845193320, 0.554217168584820]
[0.594104537120270, 0.535367271912663]
[0.635203806507664, 0.512309598462438]
[0.673942342664623, 0.485149121249596]
[0.709968282219565, 0.454077548753984]
[0.742981480671386, 0.419372062483325]
[0.772743730135128, 0.381389800885276]
[0.799086129190357, 0.340558174331952]
[0.821913031412171, 0.297361476157460]
[0.841202297595171, 0.252324606583890]
[0.857001913278751, 0.205994998255325]
[0.869423360156828, 0.158923983550780]
[0.878632400961749, 0.111648854141894]
[0.884838117000404, 0.0646767355941309]
[0.888281107786466, 0.0184711598608366]
[0.889221724966838, -0.0265580920222463]
[0.887929086978319, -0.0700616376357065]
[0.884671436749944, -0.111753702079984]
[0.879708196142373, -0.151412212133505]
[0.873283868434856, -0.188876276382474]
[0.865623767004738, -0.224041647436492]
[0.856931417622216, -0.256854783932934]
[0.847387397427031, -0.287306093145686]
[0.837149332327679, -0.315422858352193]
[0.826352768388623, -0.341262257014314]
[0.815112651941032, -0.364904771778621]
[0.803525187975441, -0.386448197733930]
[0.791669888565335, -0.406002363501787]
[0.779611666348698, -0.423684614121393]
[0.767402868254788, -0.439616051044376]
[0.755085179319361, -0.453918487702293]
[0.742691354608144, -0.466712055802455]
[0.730246758969588, -0.478113385062212]
[0.717770710165260, -0.488234274829692]
[0.705277631779699, -0.497180777550567]
[0.692778029180460, -0.505052619313248]
[0.680279305628557, -0.511942890156880]
WARNING: Output truncated!  
full_output.txt



[1, 1]
[1.10000000000000, 0.970000000000000]
[1.19554500000000, 0.927804000000000]
[1.28497621312080, 0.873492434085960]
[1.36680028644537, 0.807637039708032]
[1.43979601782619, 0.731316124196504]
[1.50310298771150, 0.646081578788237]
[1.55627813697339, 0.553876172008416]
[1.59931088626975, 0.456908486860592]
[1.63259457888104, 0.357501013484366]
[1.65685997828737, 0.257932002325746]
[1.67308302429485, 0.160292197915408]
[1.68238231362625, 0.0663734762396137]
[1.68592125935563, -0.0224008565043855]
[1.68482630644902, -0.105002516124457]
[1.68012745706242, -0.180786774834114]
[1.67272231121846, -0.249452742744653]
[1.66336100762437, -0.310986527062072]
[1.65264731227197, -0.365597542362485]
[1.64105051330292, -0.413655999832889]
[1.62892327762117, -0.455636888781669]
[1.61652168190301, -0.492073246371459]
[1.60402482357417, -0.523519544550458]
[1.59155248202296, -0.550524701108833]
[1.57918011929407, -0.573613477705975]
[1.56695106649907, -0.593274723131762]
[1.55488607519783, -0.609954906854696]
[1.54299057927490, -0.624055540821019]
[1.53126006813532, -0.635933315089653]
[1.51968396144289, -0.645902016203175]
[1.50824833135949, -0.654235522830852]
[1.49693776118464, -0.661171365685823]
[1.48573657164049, -0.666914493718286]
[1.47462959405115, -0.671641008047884]
[1.46360262583334, -0.675501713857138]
[1.45264266841168, -0.678625404254129]
[1.44173802016393, -0.681121834454926]
[1.43087827610974, -0.683084374350523]
[1.42005427051631, -0.684592346550196]
[1.40925798723655, -0.685713068420138]
[1.39848245442565, -0.686503622802859]
[1.38772163449158, -0.687012384735411]
[1.37697031609380, -0.687280331827505]
[1.36622401222828, -0.687342164891376]
[1.35547886656558, -0.687227263538872]
[1.34473156897620, -0.686960499184740]
[1.33397928038897, -0.686562925484320]
[1.32321956664723, -0.686052363855670]
[1.31245034075205, -0.685443899489551]
[1.30166981274494, -0.684750301188629]
[1.29087644643440, -0.683982376522825]
[1.28006892217795, -0.683149272144667]
[1.26924610497231, -0.682258727669061]
[1.25840701716289, -0.681317290271664]
[1.24755081515046, -0.680330496081525]
[1.23667676954131, -0.679303023518040]
[1.22578424825345, -0.678238822931444]
[1.21487270215345, -0.677141226232379]
[1.20394165285500, -0.676013039623944]

...

[-0.242728623086857, 0.279575839340331]
[-0.224841698622698, 0.302590840811220]
[-0.205134095734994, 0.325754259098821]
[-0.183540590914002, 0.348976621984423]
[-0.160002525680198, 0.372153067482177]
[-0.134469977024270, 0.395161870316031]
[-0.106904238320885, 0.417863032476618]
[-0.0772806110015262, 0.440097012012530]
[-0.0455914914017819, 0.461683683781087]
[-0.0118497160192438, 0.482421647006140]
[0.0239078986060691, 0.502088015983098]
[0.0616169181949162, 0.520438850291384]
[0.101181690554116, 0.537210396794916]
[0.142471960915090, 0.552121324054085]
[0.185319924941556, 0.564876126252334]
[0.229517983154665, 0.575169853482453]
[0.274817493846539, 0.582694283243713]
[0.320928839394969, 0.587145579917330]
[0.367523114991659, 0.588233392191804]
[0.414235710785723, 0.585691213353486]
[0.460671981323371, 0.579287680988482]
[0.506415076240046, 0.568838331585039]
[0.551035845193320, 0.554217168584820]
[0.594104537120270, 0.535367271912663]
[0.635203806507664, 0.512309598462438]
[0.673942342664623, 0.485149121249596]
[0.709968282219565, 0.454077548753984]
[0.742981480671386, 0.419372062483325]
[0.772743730135128, 0.381389800885276]
[0.799086129190357, 0.340558174331952]
[0.821913031412171, 0.297361476157460]
[0.841202297595171, 0.252324606583890]
[0.857001913278751, 0.205994998255325]
[0.869423360156828, 0.158923983550780]
[0.878632400961749, 0.111648854141894]
[0.884838117000404, 0.0646767355941309]
[0.888281107786466, 0.0184711598608366]
[0.889221724966838, -0.0265580920222463]
[0.887929086978319, -0.0700616376357065]
[0.884671436749944, -0.111753702079984]
[0.879708196142373, -0.151412212133505]
[0.873283868434856, -0.188876276382474]
[0.865623767004738, -0.224041647436492]
[0.856931417622216, -0.256854783932934]
[0.847387397427031, -0.287306093145686]
[0.837149332327679, -0.315422858352193]
[0.826352768388623, -0.341262257014314]
[0.815112651941032, -0.364904771778621]
[0.803525187975441, -0.386448197733930]
[0.791669888565335, -0.406002363501787]
[0.779611666348698, -0.423684614121393]
[0.767402868254788, -0.439616051044376]
[0.755085179319361, -0.453918487702293]
[0.742691354608144, -0.466712055802455]
[0.730246758969588, -0.478113385062212]
[0.717770710165260, -0.488234274829692]
[0.705277631779699, -0.497180777550567]
[0.692778029180460, -0.505052619313248]
[0.680279305628557, -0.511942890156880]