我正在使用scipy的BVP求解器:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_bvp.html
我遇到的问题是你只能拥有与方程一样多的边界条件。我只有一个方程,但我有两个边界条件。怎么解决这个问题?
MWE
>>> import numpy as np
>>> from scipy.integrate import solve_bvp
>>>
>>> x = np.linspace(0, 1, 100)
>>> dydx = lambda x,y: y*np.sin(x)
>>>
>>> result = solve_bvp(dydx,
... lambda ya,yb: np.array([ (ya[0]-1)**2 + (yb[0]-1)**2 ]),
... x, [np.ones(len(x))], max_nodes=100000, tol=1e-9)
>>>
>>> result
message: 'The algorithm converged to the desired accuracy.'
niter: 2
p: None
rms_residuals: array([ 3.48054730e-10, 3.47134800e-10, 3.46220750e-10,
3.45304147e-10, 3.44446495e-10, 3.43708535e-10,
3.42834209e-10, 3.41730399e-10, 3.40902853e-10,
3.40116511e-10, 3.39286663e-10, 3.38873550e-10,
3.37853506e-10, 3.36632825e-10, 3.35880059e-10,
3.35385717e-10, 3.35453551e-10, 3.34784891e-10,
3.32401725e-10, 3.34486867e-10, 3.35674629e-10,
3.37743169e-10, 3.34329677e-10, 3.29311236e-10,
3.27606354e-10, 3.28578369e-10, 3.27772742e-10,
3.26447666e-10, 3.24908674e-10, 3.24192402e-10,
3.25862692e-10, 3.28872815e-10, 3.22757465e-10,
3.21914926e-10, 3.20227078e-10, 3.23579897e-10,
3.28140843e-10, 3.18151515e-10, 3.21177949e-10,
3.16611117e-10, 3.45372059e-10, 3.18345626e-10,
3.24069081e-10, 3.32570305e-10, 3.19141250e-10,
3.14376144e-10, 3.18278959e-10, 3.11802424e-10,
3.15597596e-10, 3.22818017e-10, 3.15384028e-10,
3.17673241e-10, 3.08099021e-10, 3.11743210e-10,
3.28763320e-10, 3.24475197e-10, 3.28343741e-10,
3.25892534e-10, 3.12411478e-10, 3.37194926e-10,
3.20060651e-10, 3.03517565e-10, 3.00795182e-10,
3.06846379e-10, 3.00064770e-10, 3.05765788e-10,
2.99543196e-10, 2.98157661e-10, 2.97863071e-10,
2.96467397e-10, 3.74567928e-10, 3.24304178e-10,
3.16165056e-10, 3.02449962e-10, 2.93348900e-10,
3.08601600e-10, 2.93492038e-10, 3.11756310e-10,
2.97438508e-10, 3.17903029e-10, 3.05491804e-10,
3.02623385e-10, 3.06340149e-10, 2.94595579e-10,
2.87571373e-10, 3.03866639e-10, 3.42985927e-10,
3.21829601e-10, 3.70164964e-10, 3.53563487e-10,
3.00178404e-10, 2.83888849e-10, 2.82310753e-10,
2.85661232e-10, 3.11405296e-10, 2.80954237e-10,
2.79523163e-10, 2.80819968e-10, 2.94406497e-10,
3.19548071e-10, 2.95355340e-10, 2.77522541e-10,
2.76703591e-10, 2.88121141e-10, 2.75290617e-10,
2.84220379e-10, 2.89876300e-10, 3.14510031e-10,
3.11057911e-10, 2.72303350e-10, 2.79168046e-10,
2.90700062e-10, 2.78438999e-10, 2.68897634e-10,
2.69286657e-10, 2.90472537e-10, 2.78378707e-10,
2.97980086e-10, 2.97008148e-10, 2.65028623e-10,
2.64744165e-10, 2.69437313e-10, 2.63909411e-10,
2.62339786e-10, 2.71045386e-10, 2.65850861e-10,
2.78162780e-10, 2.61231989e-10, 2.70109868e-10,
2.61595375e-10, 2.59299272e-10, 2.65106316e-10,
2.74283076e-10, 2.86861196e-10, 3.03175803e-10,
2.58290170e-10, 3.61324845e-10, 3.39239278e-10,
2.91296094e-10, 2.83918017e-10, 4.52002829e-10,
2.52915179e-10, 3.13709791e-10, 3.72555078e-10,
2.48903834e-10, 2.58089690e-10, 2.86634265e-10,
2.60879823e-10, 2.64643448e-10, 3.03583577e-10,
5.12385186e-10, 2.42415186e-10, 3.47677749e-10,
2.41037177e-10, 2.91624837e-10, 2.88486833e-10,
2.97731066e-10, 3.46537042e-10, 2.44416103e-10,
4.29099468e-10, 4.71320607e-10, 2.97672164e-10,
3.26787171e-10, 2.34920240e-10, 2.64792458e-10,
2.91952218e-10, 2.47064463e-10, 2.34000456e-10,
4.10948830e-10, 2.36520479e-10, 3.42444147e-10,
2.76749245e-10, 2.51379106e-10, 2.40093828e-10,
2.72602754e-10, 3.94004751e-10, 2.84796018e-10,
3.72431030e-10, 2.23313796e-10, 3.32252341e-10,
3.34369044e-10, 2.63230702e-10, 2.17694780e-10,
3.25346854e-10, 2.64869219e-10, 3.51158895e-10,
3.60872478e-10, 3.09047143e-10, 2.22308395e-10,
2.43344334e-10, 2.16527726e-10, 2.98642975e-10,
2.77152047e-10, 2.66161092e-10, 2.91230604e-10,
2.37973344e-10, 2.95802884e-10, 2.78890213e-10,
2.19485810e-10, 3.53536609e-10, 2.16716319e-10,
2.51682560e-10, 2.04749227e-10, 4.31531575e-10,
3.47595602e-10, 2.38112586e-10, 1.92156254e-10,
2.46451083e-10, 2.99903096e-10, 1.90926751e-10,
2.05652721e-10, 2.33415220e-10, 2.43209873e-10,
1.85670073e-10, 2.02780645e-10, 1.89290313e-10,
1.81291292e-10, 1.77940599e-10, 3.60470288e-10,
3.28978503e-10, 1.74204497e-10, 1.95779041e-10,
2.50524362e-10, 2.49249184e-10, 1.67522152e-10,
1.68202192e-10, 1.82172067e-10, 1.77510490e-10,
1.62468247e-10, 1.75426885e-10, 3.24084379e-10,
2.21087707e-10, 1.88843987e-10, 2.57800867e-10,
1.53483353e-10, 1.80491618e-10, 2.28820880e-10,
2.32095332e-10, 1.90031952e-10, 1.46493968e-10,
2.00403717e-10, 3.23811210e-10, 1.90421082e-10,
1.45237509e-10, 1.67970046e-10, 1.49189288e-10,
1.39748871e-10, 1.40621758e-10, 1.33316350e-10,
2.22781676e-10, 1.31021647e-10, 2.12758988e-10,
1.38894682e-10, 1.75219768e-10, 1.78296709e-10,
3.67044064e-10, 2.04279379e-10, 2.11899286e-10,
1.59322174e-10, 1.21129350e-10, 1.18003803e-10,
1.42850831e-10, 1.33020880e-10, 1.27620814e-10,
1.48379719e-10, 3.35008994e-10, 3.31675208e-10,
2.49871984e-10, 1.06526186e-10, 1.57190187e-10,
9.38688508e-11, 2.16167913e-10, 1.12548066e-10,
1.98572296e-10, 2.12773340e-10, 3.09554965e-10,
2.32665662e-10, 8.05365861e-11, 2.71090303e-10,
1.60686511e-10, 1.20088934e-10, 3.23772391e-10,
2.01129249e-10, 3.04370308e-10, 6.75862037e-11,
7.60074235e-11, 1.55486106e-10, 2.24650749e-10,
2.10826836e-10, 3.75354523e-10, 1.48504437e-10,
1.65019969e-10, 7.52309342e-11, 3.59188285e-10,
1.55801401e-10, 1.52568581e-10, 5.38230045e-11])
sol: <scipy.interpolate.interpolate.PPoly object at 0x2ad860930d58>
status: 0
success: True
x: array([ 0. , 0.003367 , 0.00673401, 0.01010101, 0.01346801,
0.01683502, 0.02020202, 0.02356902, 0.02693603, 0.03030303,
0.03367003, 0.03703704, 0.04040404, 0.04377104, 0.04713805,
0.05050505, 0.05387205, 0.05723906, 0.06060606, 0.06397306,
0.06734007, 0.07070707, 0.07407407, 0.07744108, 0.08080808,
0.08417508, 0.08754209, 0.09090909, 0.09427609, 0.0976431 ,
0.1010101 , 0.1043771 , 0.10774411, 0.11111111, 0.11447811,
0.11784512, 0.12121212, 0.12457912, 0.12794613, 0.13131313,
0.13468013, 0.13804714, 0.14141414, 0.14478114, 0.14814815,
0.15151515, 0.15488215, 0.15824916, 0.16161616, 0.16498316,
0.16835017, 0.17171717, 0.17508418, 0.17845118, 0.18181818,
0.18518519, 0.18855219, 0.19191919, 0.1952862 , 0.1986532 ,
0.2020202 , 0.20538721, 0.20875421, 0.21212121, 0.21548822,
0.21885522, 0.22222222, 0.22558923, 0.22895623, 0.23232323,
0.23569024, 0.23905724, 0.24242424, 0.24579125, 0.24915825,
0.25252525, 0.25589226, 0.25925926, 0.26262626, 0.26599327,
0.26936027, 0.27272727, 0.27609428, 0.27946128, 0.28282828,
0.28619529, 0.28956229, 0.29292929, 0.2962963 , 0.2996633 ,
0.3030303 , 0.30639731, 0.30976431, 0.31313131, 0.31649832,
0.31986532, 0.32323232, 0.32659933, 0.32996633, 0.33333333,
0.33670034, 0.34006734, 0.34343434, 0.34680135, 0.35016835,
0.35353535, 0.35690236, 0.36026936, 0.36363636, 0.36700337,
0.37037037, 0.37373737, 0.37710438, 0.38047138, 0.38383838,
0.38720539, 0.39057239, 0.39393939, 0.3973064 , 0.4006734 ,
0.4040404 , 0.40740741, 0.41077441, 0.41414141, 0.41750842,
0.42087542, 0.42424242, 0.42760943, 0.43097643, 0.43434343,
0.43771044, 0.44107744, 0.44444444, 0.44781145, 0.45117845,
0.45454545, 0.45791246, 0.46127946, 0.46464646, 0.46801347,
0.47138047, 0.47474747, 0.47811448, 0.48148148, 0.48484848,
0.48821549, 0.49158249, 0.49494949, 0.4983165 , 0.5016835 ,
0.50505051, 0.50841751, 0.51178451, 0.51515152, 0.51851852,
0.52188552, 0.52525253, 0.52861953, 0.53198653, 0.53535354,
0.53872054, 0.54208754, 0.54545455, 0.54882155, 0.55218855,
0.55555556, 0.55892256, 0.56228956, 0.56565657, 0.56902357,
0.57239057, 0.57575758, 0.57912458, 0.58249158, 0.58585859,
0.58922559, 0.59259259, 0.5959596 , 0.5993266 , 0.6026936 ,
0.60606061, 0.60942761, 0.61279461, 0.61616162, 0.61952862,
0.62289562, 0.62626263, 0.62962963, 0.63299663, 0.63636364,
0.63973064, 0.64309764, 0.64646465, 0.64983165, 0.65319865,
0.65656566, 0.65993266, 0.66329966, 0.66666667, 0.67003367,
0.67340067, 0.67676768, 0.68013468, 0.68350168, 0.68686869,
0.69023569, 0.69360269, 0.6969697 , 0.7003367 , 0.7037037 ,
0.70707071, 0.71043771, 0.71380471, 0.71717172, 0.72053872,
0.72390572, 0.72727273, 0.73063973, 0.73400673, 0.73737374,
0.74074074, 0.74410774, 0.74747475, 0.75084175, 0.75420875,
0.75757576, 0.76094276, 0.76430976, 0.76767677, 0.77104377,
0.77441077, 0.77777778, 0.78114478, 0.78451178, 0.78787879,
0.79124579, 0.79461279, 0.7979798 , 0.8013468 , 0.8047138 ,
0.80808081, 0.81144781, 0.81481481, 0.81818182, 0.82154882,
0.82491582, 0.82828283, 0.83164983, 0.83501684, 0.83838384,
0.84175084, 0.84511785, 0.84848485, 0.85185185, 0.85521886,
0.85858586, 0.86195286, 0.86531987, 0.86868687, 0.87205387,
0.87542088, 0.87878788, 0.88215488, 0.88552189, 0.88888889,
0.89225589, 0.8956229 , 0.8989899 , 0.9023569 , 0.90572391,
0.90909091, 0.91245791, 0.91582492, 0.91919192, 0.92255892,
0.92592593, 0.92929293, 0.93265993, 0.93602694, 0.93939394,
0.94276094, 0.94612795, 0.94949495, 0.95286195, 0.95622896,
0.95959596, 0.96296296, 0.96632997, 0.96969697, 0.97306397,
0.97643098, 0.97979798, 0.98316498, 0.98653199, 0.98989899,
0.99326599, 0.996633 , 1. ])
y: array([[ 0.79388397, 0.79388847, 0.79390197, 0.79392447, 0.79395597,
0.79399647, 0.79404598, 0.79410449, 0.794172 , 0.79424853,
0.79433406, 0.7944286 , 0.79453215, 0.79464471, 0.7947663 ,
0.7948969 , 0.79503653, 0.79518518, 0.79534287, 0.79550958,
0.79568534, 0.79587013, 0.79606397, 0.79626686, 0.7964788 ,
0.7966998 , 0.79692987, 0.797169 , 0.79741721, 0.7976745 ,
0.79794087, 0.79821634, 0.7985009 , 0.79879457, 0.79909735,
0.79940925, 0.79973028, 0.80006043, 0.80039973, 0.80074817,
0.80110577, 0.80147253, 0.80184846, 0.80223358, 0.80262788,
0.80303138, 0.80344409, 0.80386601, 0.80429716, 0.80473755,
0.80518718, 0.80564606, 0.80611421, 0.80659164, 0.80707835,
0.80757437, 0.80807969, 0.80859433, 0.8091183 , 0.80965162,
0.8101943 , 0.81074634, 0.81130776, 0.81187857, 0.81245879,
0.81304843, 0.8136475 , 0.81425602, 0.814874 , 0.81550144,
0.81613838, 0.81678482, 0.81744077, 0.81810625, 0.81878128,
0.81946586, 0.82016002, 0.82086378, 0.82157714, 0.82230012,
0.82303274, 0.82377501, 0.82452696, 0.8252886 , 0.82605994,
0.826841 , 0.8276318 , 0.82843236, 0.82924269, 0.83006282,
0.83089275, 0.83173252, 0.83258213, 0.83344161, 0.83431098,
0.83519025, 0.83607944, 0.83697858, 0.83788768, 0.83880677,
0.83973586, 0.84067497, 0.84162413, 0.84258336, 0.84355267,
0.84453209, 0.84552164, 0.84652134, 0.84753122, 0.84855129,
0.84958158, 0.85062211, 0.8516729 , 0.85273397, 0.85380536,
0.85488708, 0.85597915, 0.85708161, 0.85819447, 0.85931775,
0.86045149, 0.86159571, 0.86275043, 0.86391567, 0.86509147,
0.86627784, 0.86747482, 0.86868242, 0.86990068, 0.87112962,
0.87236927, 0.87361965, 0.8748808 , 0.87615273, 0.87743548,
0.87872907, 0.88003353, 0.88134889, 0.88267518, 0.88401242,
0.88536065, 0.88671989, 0.88809017, 0.88947152, 0.89086397,
0.89226754, 0.89368228, 0.89510821, 0.89654536, 0.89799375,
0.89945343, 0.90092442, 0.90240675, 0.90390045, 0.90540555,
0.9069221 , 0.90845011, 0.90998962, 0.91154066, 0.91310327,
0.91467748, 0.91626331, 0.91786081, 0.91947001, 0.92109093,
0.92272362, 0.92436811, 0.92602442, 0.9276926 , 0.92937269,
0.9310647 , 0.93276869, 0.93448468, 0.93621271, 0.93795282,
0.93970504, 0.9414694 , 0.94324595, 0.94503471, 0.94683573,
0.94864904, 0.95047469, 0.95231269, 0.9541631 , 0.95602595,
0.95790128, 0.95978913, 0.96168953, 0.96360252, 0.96552814,
0.96746643, 0.96941743, 0.97138117, 0.9733577 , 0.97534706,
0.97734928, 0.97936441, 0.98139248, 0.98343353, 0.98548761,
0.98755476, 0.98963501, 0.99172841, 0.993835 , 0.99595481,
0.9980879 , 1.0002343 , 1.00239405, 1.0045672 , 1.00675379,
1.00895385, 1.01116744, 1.0133946 , 1.01563536, 1.01788978,
1.02015789, 1.02243974, 1.02473537, 1.02704483, 1.02936815,
1.03170539, 1.03405659, 1.03642179, 1.03880103, 1.04119437,
1.04360185, 1.0460235 , 1.04845939, 1.05090954, 1.05337402,
1.05585286, 1.05834611, 1.06085381, 1.06337602, 1.06591277,
1.06846412, 1.07103012, 1.0736108 , 1.07620622, 1.07881642,
1.08144145, 1.08408136, 1.0867362 , 1.08940601, 1.09209084,
1.09479074, 1.09750576, 1.10023595, 1.10298135, 1.10574202,
1.108518 , 1.11130934, 1.11411609, 1.1169383 , 1.11977602,
1.1226293 , 1.12549819, 1.12838274, 1.13128299, 1.13419901,
1.13713083, 1.14007851, 1.14304211, 1.14602166, 1.14901722,
1.15202884, 1.15505658, 1.15810048, 1.1611606 , 1.16423698,
1.16732967, 1.17043874, 1.17356423, 1.17670619, 1.17986467,
1.18303973, 1.18623141, 1.18943978, 1.19266488, 1.19590676,
1.19916548, 1.20244108, 1.20573363, 1.20904318, 1.21236977,
1.21571346, 1.2190743 , 1.22245235, 1.22584765, 1.22926027,
1.23269025, 1.23613766, 1.23960253, 1.24308492, 1.2465849 ,
1.25010251, 1.2536378 , 1.25719083]])
yp: array([[ 0. , 0.00267302, 0.0053461 , 0.0080193 , 0.01069269,
0.01336631, 0.01604024, 0.01871453, 0.02138925, 0.02406445,
0.0267402 , 0.02941655, 0.03209358, 0.03477132, 0.03744986,
0.04012924, 0.04280954, 0.0454908 , 0.04817309, 0.05085648,
0.05354102, 0.05622677, 0.05891379, 0.06160215, 0.0642919 ,
0.06698311, 0.06967583, 0.07237013, 0.07506607, 0.0777637 ,
0.0804631 , 0.08316431, 0.08586741, 0.08857244, 0.09127948,
0.09398858, 0.0966998 , 0.09941321, 0.10212887, 0.10484683,
0.10756715, 0.11028991, 0.11301515, 0.11574295, 0.11847335,
0.12120642, 0.12394223, 0.12668083, 0.12942228, 0.13216665,
0.134914 , 0.13766438, 0.14041786, 0.1431745 , 0.14593436,
0.1486975 , 0.15146398, 0.15423387, 0.15700722, 0.1597841 ,
0.16256456, 0.16534867, 0.16813649, 0.17092808, 0.1737235 ,
0.17652281, 0.17932607, 0.18213335, 0.18494471, 0.1877602 ,
0.1905799 , 0.19340385, 0.19623212, 0.19906478, 0.20190187,
0.20474348, 0.20758965, 0.21044044, 0.21329593, 0.21615617,
0.21902122, 0.22189114, 0.22476599, 0.22764585, 0.23053076,
0.23342079, 0.236316 , 0.23921645, 0.2421222 , 0.24503332,
0.24794987, 0.2508719 , 0.25379948, 0.25673268, 0.25967155,
0.26261615, 0.26556655, 0.2685228 , 0.27148497, 0.27445313,
0.27742732, 0.28040762, 0.28339409, 0.28638678, 0.28938576,
0.29239109, 0.29540283, 0.29842105, 0.3014458 , 0.30447715,
0.30751515, 0.31055988, 0.31361139, 0.31666974, 0.31973499,
0.32280722, 0.32588647, 0.32897281, 0.3320663 , 0.33516701,
0.33827498, 0.3413903 , 0.34451301, 0.34764319, 0.35078088,
0.35392616, 0.35707908, 0.3602397 , 0.3634081 , 0.36658432,
0.36976843, 0.37296049, 0.37616057, 0.37936872, 0.382585 ,
0.38580948, 0.38904223, 0.39228329, 0.39553273, 0.39879061,
0.402057 , 0.40533195, 0.40861553, 0.4119078 , 0.41520881,
0.41851863, 0.42183733, 0.42516495, 0.42850157, 0.43184723,
0.43520202, 0.43856597, 0.44193917, 0.44532166, 0.4487135 ,
0.45211476, 0.45552551, 0.45894578, 0.46237566, 0.4658152 ,
0.46926446, 0.47272349, 0.47619237, 0.47967114, 0.48315988,
0.48665863, 0.49016747, 0.49368644, 0.49721562, 0.50075505,
0.5043048 , 0.50786493, 0.5114355 , 0.51501656, 0.51860818,
0.52221041, 0.52582331, 0.52944695, 0.53308138, 0.53672666,
0.54038285, 0.54405001, 0.54772819, 0.55141745, 0.55511786,
0.55882946, 0.56255232, 0.5662865 , 0.57003205, 0.57378903,
0.5775575 , 0.58133751, 0.58512912, 0.58893239, 0.59274738,
0.59657414, 0.60041272, 0.60426319, 0.6081256 , 0.61200001,
0.61588646, 0.61978503, 0.62369576, 0.6276187 , 0.63155392,
0.63550147, 0.6394614 , 0.64343376, 0.64741862, 0.65141602,
0.65542602, 0.65944867, 0.66348403, 0.66753215, 0.67159308,
0.67566687, 0.67975358, 0.68385327, 0.68796597, 0.69209174,
0.69623064, 0.70038272, 0.70454802, 0.7087266 , 0.7129185 ,
0.71712379, 0.7213425 , 0.72557469, 0.72982041, 0.7340797 ,
0.73835262, 0.74263921, 0.74693953, 0.75125361, 0.75558151,
0.75992327, 0.76427895, 0.76864858, 0.77303222, 0.7774299 ,
0.78184168, 0.7862676 , 0.79070771, 0.79516204, 0.79963065,
0.80411358, 0.80861086, 0.81312256, 0.81764869, 0.82218932,
0.82674447, 0.8313142 , 0.83589854, 0.84049753, 0.84511122,
0.84973964, 0.85438283, 0.85904083, 0.86371368, 0.86840142,
0.87310408, 0.8778217 , 0.88255432, 0.88730198, 0.89206471,
0.89684254, 0.90163551, 0.90644365, 0.911267 , 0.91610559,
0.92095945, 0.92582862, 0.93071312, 0.93561298, 0.94052825,
0.94545894, 0.95040508, 0.95536671, 0.96034386, 0.96533654,
0.97034479, 0.97536863, 0.98040809, 0.98546319, 0.99053396,
0.99562042, 1.0007226 , 1.00584051, 1.01097418, 1.01612363,
1.02128888, 1.02646995, 1.03166686, 1.03687962, 1.04210827,
1.0473528 , 1.05261324, 1.0578896 ]])
如您所见,y与y(x=0) = y(x=1) = 1
的边界条件相距甚远。
答案 0 :(得分:1)
如果为一阶ODE指定两个边界条件y(0)= 1和y(1)= 1,那么通常问题是超定的并且没有解。如果仅指定初始条件y(0)= y0,则会出现一阶初始值问题。实际上,在这种情况下,您可以导出精确解:y(x)= y0 * exp(-cos(x))。