'Physics Python Formula

I am a college student. I need to compute this formula for my final year Physics project. I am putting my own version which is having a math domain error.

FORMULA : https://i.stack.imgur.com/wGhG0.jpg

The symbol shown is finite products which works same as summation sign but instead of adding, multiplication takes place. And instead of infinity I have to take values from 0 to 100.*

def funq(q, x):
    return (math.sqrt(1 - q) / 2 * math.pi * math.sqrt(4 - (1 - q) * (x ** 2))) * nprod(lambda i: (1 - q ** (i + 1))*((1 + q ** i) ** 2) - (1 - q)*(q ** i)*(x ** 2), [0, 100])

I have values for x and q, and here I have to take i from 0 to 100.

xs = [-1.9786357294030505, -1.8729683005605666, -1.8690079734953249, -1.7893930922097478, -1.7786223508087187, -1.7330418476321756, -1.7218150017905753, -1.7053215143651612, -1.6859860461491698, -1.6440572818865058, -1.6284242718994277, -1.594340198236287, -1.583713661880595, -1.5662028064425124, -1.511369193363463, -1.4959328789222448, -1.4756020410385255, -1.4362949249640893, -1.423699326374759, -1.3920503186588522, -1.3666704786700927, -1.3392600432337527, -1.3188944726286376, -1.300630969628771, -1.284216913905989, -1.2671896486219765, -1.2368473426034123, -1.235421991642431, -1.1970513167149672, -1.163387360445743, -1.1524460267982806, -1.13212800790605, -1.11682277889514, -1.0932584182021468, -1.0719251220099668, -1.0678870348976006, -1.0210296076133556, -1.0130488003608291, -0.9975858444089151, -0.9796452267641969, -0.9530125782990486, -0.9464384291595466, -0.9191313448853328, -0.9038898666356475, -0.8902743815564222, -0.8674005928510681, -0.8508650887302857, -0.8200469178891021, -0.8085708326297844, -0.7881170124056511, -0.7799411570886873, -0.7661606085504135, -0.7618458977422593, -0.7492332851473245, -0.7373083334809616, -0.719374597403646, -0.7026302150707191, -0.6729458730969575, -0.6559214240063347, -0.6493288264029489, -0.6218035549315963, -0.607466462637045, -0.596294879772371, -0.5713878489863752, -0.5598867615279391, -0.5572092841273873, -0.5273247323025781, -0.5221465145961504, -0.4925721990514733, -0.48310483493375744, -0.4718028670160281, -0.44426669977293703, -0.4386304188536966, -0.43405364241292016, -0.4021647180497939, -0.3927630747654775, -0.3707640646729126, -0.35506873216266965, -0.34834585664141654, -0.3319465767329759, -0.2894674105765397, -0.2817473493386308, -0.26957856656820584, -0.2615569395897469, -0.25386346475088906, -0.23528915363262143, -0.21698584251388872, -0.1933748674795559, -0.18559018928903234, -0.17160387866256502, -0.1687830111167416, -0.14974728885496646, -0.13804745514819466, -0.11923132937556802, -0.10176330992119202, -0.08467961756036736, -0.0635710853983301, -0.04620384807512924, -0.023706228233325653, -0.020329108587452387, -0.004536805620385409, 0.01049134854325218, 0.04292771525256894, 0.06067759178398313, 0.06822867908723125, 0.09118306217222992, 0.10708472302097773, 0.12057759872860745, 0.13207640947677135, 0.15166551213353896, 0.17118988666950177, 0.17713745442040899, 0.19965260497566134, 0.2134119323494147, 0.23784494435362605, 0.2551296841720161, 0.26428140746568396, 0.26853941563033434, 0.2883002215813374, 0.3088450422437123, 0.32659857314747376, 0.35028020322764974, 0.35652392405534983, 0.37353733908535114, 0.38093124895960145, 0.3888334202882138, 0.43580283094851185, 0.4471450889908507, 0.46585500567028143, 0.5014418423782477, 0.5051994192994206, 0.5312947926610357, 0.5495070698301275, 0.5503358521115466, 0.5567675709547716, 0.593262743016464, 0.5957398500355201, 0.6148641411496494, 0.6215789147290754, 0.6262076647002017, 0.6563209774380261, 0.6732407668582557, 0.694602036698193, 0.7105886846018437, 0.7246384345455785, 0.7440648676491575, 0.7576474680600296, 0.7809521435309291, 0.7907796476189285, 0.7974666399351398, 0.830233890957038, 0.8583238856991258, 0.8753678555773454, 0.8834793982320464, 0.9079280272571449, 0.9095178763387498, 0.9216786507153699, 0.9361529250822589, 0.9517403164092609, 0.9707510788524722, 0.9813086631062877, 1.0009213904099536, 1.0271197471735438, 1.0454782328986996, 1.0589826548690298, 1.0738076787890236, 1.0939970755818516, 1.108844856545789, 1.1242177261974418, 1.1469475819883208, 1.1569086631966876, 1.184912907917583, 1.206486214117146, 1.2187025753360223, 1.2669839237894613, 1.2846273014950762, 1.3182316671735366, 1.32732883588292, 1.3453440614407257, 1.3686243254134494, 1.3707222594460755, 1.4013900463539046, 1.4053423560030363, 1.4425665235329186, 1.4682651589031035, 1.4833174961903184, 1.510306637513224, 1.5394845108942132, 1.552577965032721, 1.570537066079267, 1.6046955859559133, 1.6341308355418969, 1.6525106440774544, 1.6791516946558083, 1.7464079020909997, 1.776987500944659, 1.8163870734766445, 1.8599053537185501, 1.876231778796384, 1.9458011294201891, -1.9512196654751857, -1.8829812085480147, -1.8576710431594026, -1.7962607878829076, -1.7906921105373508, -1.7807662079136575, -1.7243537674252296, -1.6653760064322933, -1.6247791399291813, -1.6131800223977202, -1.5992690882006375, -1.5711596720979557, -1.5423532598624516, -1.5366416410035018, -1.504960954218726, -1.4924796299349394, -1.4651134679176212, -1.454086257567312, -1.435312299789483, -1.3900656838493024, -1.3710456440546588, -1.3289367992734276, -1.3175853505277841, -1.2935618896837286, -1.2911125035321889, -1.2705424625860116, -1.2495382702510687, -1.1913798629046468, -1.1838747404652799, -1.1545896195973815, -1.1411111303499946, -1.1295376236771988, -1.1133537812338583, -1.088174769710425, -1.0635278526778984, -1.0476645832032065, -1.0391589671067623, -1.024214524630082, -1.0172424281544814, -1.000235923512485, -0.9508581215025034, -0.9398414654598437, -0.9194964159277919, -0.9134585512802674, -0.8934873866985384, -0.8814068284436899, -0.8780235651897508, -0.8606464532377365, -0.8356762831449271, -0.8187239412996997, -0.7854978612688941, -0.7828386290808195, -0.7690085876655378, -0.7421029961018879, -0.7311170128877692, -0.7264957952911963, -0.7026853588698583, -0.6818444893142, -0.6721154623517708, -0.657078101256421, -0.6452274971677785, -0.6300075175829053, -0.6242267077379532, -0.5721969221810158, -0.5662035998641474, -0.5479259590977337, -0.5314602882649556, -0.5115321242783482, -0.4983577363159967, -0.4855819569700855, -0.48049012538376157, -0.4705180532386064, -0.44026650027082903, -0.435885161812978, -0.41180385376632433, -0.4017315540454998, -0.38747272372482705, -0.3759596980455016, -0.35489972421863536, -0.32461587122331836, -0.3098980922570402, -0.30758164674256944, -0.2822384073202352, -0.2656467415193894, -0.23710268441490095, -0.21537502792932678, -0.20653737924922524, -0.18828314947264962, -0.17863010696438195, -0.16565457795453492, -0.12727343410031944, -0.12125519683707242, -0.11572044525666327, -0.10039113723818469, -0.08215421819779734, -0.07462269279234593, -0.04733697243495624, -0.03902256229136341, -0.015004607861846557, 0.0023866686310914987, 0.016905251620411982, 0.03633573190335912, 0.04513078233697063, 0.06251138849975102, 0.07288973913733753, 0.08478810329844741, 0.11787454997841305, 0.1278262739774144, 0.13199265819356742, 0.15351161957574785, 0.16423257996738377, 0.1902837083202764, 0.19444594881545285, 0.22069844718453066, 0.2342673779194781, 0.2432229363065642, 0.25656196352730404, 0.2748011668035119, 0.29476629829733686, 0.3152508033830516, 0.3390860976090646, 0.34529893266442696, 0.3509103613720826, 0.3567298461252108, 0.38524111994610016, 0.3984287333260647, 0.4215287545280487, 0.42624162956106615, 0.44342322691656655, 0.46815779770191773, 0.4826276751528516, 0.48736326010167075, 0.5270847559132682, 0.535137069854498, 0.5597852966648887, 0.5636516152920249, 0.5891497307041484, 0.60387281563308, 0.6122258162432502, 0.622420591346527, 0.6425499822557241, 0.6470898125562051, 0.6749954254362208, 0.6906985075158013, 0.7111208770900466, 0.7259954339219178, 0.7353307943827243, 0.7417959844098685, 0.7773497993802436, 0.804518457940357, 0.8125382416356816, 0.8357005127959714, 0.8497608874587113, 0.877727667464255, 0.8991535828185762, 0.9028047774076086, 0.9201981762415962, 0.9347787953496884, 0.9431830927841084, 0.9734287272500868, 0.9853110402483333, 1.0185984653893043, 1.0330876627603427, 1.0440564887048558, 1.0678777326525455, 1.0799832507864535, 1.097210140121914, 1.1151293673809275, 1.1476624065213055, 1.171885726256288, 1.1945489498466135, 1.2042165808436103, 1.223472010303144, 1.2428769260838406, 1.2722914813843251, 1.2861144376992115, 1.2911038312520828, 1.324115710357473, 1.3445670941521717, 1.3620424936417799, 1.4032442887281618, 1.4262897158434138, 1.43564934224993, 1.4450583046652594, 1.4898334852707136, 1.4927707935477652, 1.520810157082525, 1.5367811961409679, 1.552026804662004, 1.6053917806651012, 1.6402918617256708, 1.6761280178591647, 1.6923263924096053, 1.6986424433215552, 1.710664592743046, 1.7416599676870563, 1.7963775987522719, 1.8268791635346637, 1.8751778855549728, 1.981682354314677, -1.9720118878290451, -1.939537662618986, -1.8918865724553584, -1.829877703387402, -1.7431576040339352, -1.7306999822153466, -1.725962554470109, -1.6955865422202412, -1.6874714573128762, -1.6564596133447511, -1.6287728876605636, -1.5687299291185692, -1.5500896765665118, -1.5041200129610381, -1.48815635666796, -1.4784514793204815, -1.4631104994968076, -1.4320533545530292, -1.385389061180228, -1.3756431584361017, -1.3407874937789346, -1.33089680314093, -1.3219489713300154, -1.3113647860494129, -1.2820497525693115, -1.2651759076742832, -1.2509187718941184, -1.2152994934030503, -1.1970958921293093, -1.1722115000513733, -1.1389481216517459, -1.124402448818879, -1.1108170242758857, -1.0910330538373234, -1.0852000040036263, -1.048868398984999, -1.037936575357004, -1.0184332805190326, -1.0040975836663302, -0.9908621277308675, -0.9808689639791376, -0.9576203771413969, -0.9383574827273514, -0.9241390631756303, -0.9006653561377413, -0.8882296350415737, -0.863499813984361, -0.8629738297540374, -0.832724843648317, -0.7954918552313025, -0.7841259500061021, -0.7629012968173354, -0.7396302666131434, -0.7325973549311713, -0.7172558883528847, -0.7035977546489376, -0.681718470024906, -0.6655340199032569, -0.6450940866579479, -0.6359437971536883, -0.6212006386783995, -0.5998238924801844, -0.5968507213695506, -0.5858328985138637, -0.5672812914958087, -0.5556718857232429, -0.527397662332296, -0.5054835290093602, -0.5002298161775866, -0.4819563855253971, -0.46731198577965777, -0.44735410123493013, -0.4359610933335695, -0.4267388065351008, -0.4100386108705584, -0.3777458706265244, -0.3660746444937139, -0.3434582909646087, -0.3251968641014367, -0.3209015434690784, -0.3129616372834409, -0.28342622089649283, -0.2711549862793822, -0.26422374179577857, -0.2572621692963007, -0.23383676389842692, -0.22255734057700996, -0.20332035913196134, -0.17902737216651185, -0.16350716516250746, -0.14985383910405983, -0.14177492514618775, -0.11738154792002622, -0.1080138817434151, -0.09178597250488336, -0.07086476635560314, -0.05080997310184168, -0.034820014063490716, -0.018611211144636736, 0.0028377929901877304, 0.0075485897441987596, 0.036178856878983506, 0.041080399335373295, 0.05476190645467531, 0.06949732553710167, 0.09564050628836183, 0.10461640687798392, 0.1178735335311192, 0.12380142675426353, 0.16284867195120775, 0.16645355064195846, 0.17563199784704414, 0.1902197422150256, 0.20752052833888784, 0.22138309372887924, 0.22636331368429083, 0.24261264064241983, 0.2556095107016821, 0.28522514338235855, 0.2982192111742722, 0.31423811916673333, 0.33525714606469353, 0.3627991090366422, 0.37870349174770274, 0.38889078665045085, 0.4005697670980977, 0.4072415222178772, 0.4309877730560121, 0.4566410063350807, 0.47269491516977874, 0.4884074671976161, 0.48963567032081695, 0.5061463389521641, 0.5137757976539188, 0.5320778362867615, 0.5663552383156409, 0.5913098355667258, 0.6001420620215526, 0.6062502577529896, 0.6228155322803758, 0.6566945705929244, 0.6701040912330436, 0.6856301582312107, 0.6975590484067273, 0.7140459359536921, 0.7337194009538845, 0.74478975523831, 0.7645867010719698, 0.7750346797057056, 0.7865373723034326, 0.800430103974259, 0.8389871896871637, 0.8568161836747437, 0.8753518460262228, 0.8845545677139671, 0.8960922464554294, 0.9031465082720954, 0.921694852314396, 0.9520374908991852, 0.9529355500377263, 1.0024617265875448, 1.0031624720038754, 1.029123254557672, 1.0502250251123864, 1.0830245555662672, 1.091864291075987, 1.1164219122856645, 1.1246840470826236, 1.153128780982803, 1.1587867797247688, 1.1817350579984447, 1.1891237906787095, 1.2200203479054452, 1.2401409256884295, 1.2556173762573795, 1.2784656407350519, 1.3029409978443105, 1.3150519586420686, 1.3426738291642524, 1.3550941015704991, 1.3801928137282742, 1.3880017332550125, 1.4117247676640234, 1.4256158120335196, 1.4976831924466858, 1.504045440500496, 1.5156581232969064, 1.5475051109944318, 1.5991000053604998, 1.6128701172592261, 1.640789269860826, 1.6547622923153782, 1.6899389055622647, 1.701898602409724, 1.7429636984357195, 1.783109902918529, 1.8224037985924213, 1.8651023143071406, 1.882137792076811, 1.9153278741127084, -1.9680191060577226, -1.9126026527271072, -1.8334286199887309, -1.8241237887379385, -1.794184436146479, -1.7538289650308811, -1.7281647807488745, -1.6859644946612475, -1.6750040533898938, -1.6166876180333731, -1.5986641531035763, -1.5537851220190246, -1.5344288522507674, -1.521861828695099, -1.4759762113534969, -1.453758749720799, -1.439204938020756, -1.4297947093230785, -1.4115802503490564, -1.3735768271594573, -1.361637313547599, -1.3224119925573916, -1.319818048911366, -1.3024603845783274, -1.280256346179591, -1.2750832311816191, -1.2434250964152074, -1.2245082926083042, -1.2050499728465303, -1.170563404213588, -1.165842914833474, -1.1377064598669886, -1.1178582479336179, -1.1012643829403204, -1.0919141814018005, -1.0544085839943336, -1.037952006198196, -1.0262759120459284, -1.0019519406226065, -0.9878780898203889, -0.9683529665381814, -0.9500457734768505, -0.9342777434689193, -0.9088480755034373, -0.8979991287618161, -0.8936633845363421, -0.8876255399886649, -0.852112186521209, -0.8373428687942521, -0.820532657082618, -0.8081499271450818, -0.7844370520522047, -0.7655711670704329, -0.7436257378821143, -0.7230913022880837, -0.716434050330068, -0.700083428475055, -0.6962593478978849, -0.664984389239175, -0.6376738086551791, -0.6297033847568315, -0.6138416596953994, -0.6067855797519732, -0.5977560157797988, -0.5897164989386259, -0.5656337041570387, -0.5461523313822663, -0.5231978899650591, -0.5155822277135736, -0.49958237424549473, -0.4696828294973386, -0.4538342164774549, -0.44082017033967275, -0.4237959706995717, -0.4028931846342117, -0.3878129828344584, -0.3825246254290875, -0.35919459854122626, -0.3257054319506828, -0.318692137282108, -0.2976055202840502, -0.27713076425571637, -0.26515410549008617, -0.26110276681620914, -0.23900592333412507, -0.23254372709987267, -0.21063055736241332, -0.20217795172571545, -0.1794864955501572, -0.16303599882697292, -0.14578257671931416, -0.13329476248452268, -0.12635479868141825, -0.10298880221144803, -0.07316094984524871, -0.060050811565541914, -0.045230718088655315, -0.04124639580826888, -0.02310287122617314, -0.013327663721056818, 0.018304292985624727, 0.03285586646353029, 0.04891340910985916, 0.054648379594054365, 0.08375779059464528, 0.11309187558430218, 0.12157397032079537, 0.13546513208058603, 0.14523943550352467, 0.16964426060085921, 0.172871660981079, 0.19134774160629572, 0.20345763626868543, 0.21688655867307643, 0.24617074201127115, 0.2712045734559311, 0.27498451306437616, 0.2800374378397933, 0.29587210980636686, 0.3227205590991154, 0.342726849996086, 0.3577324509196144, 0.3632347498651851, 0.3807181798354601, 0.38279256257420624, 0.39150259750718985, 0.4122450946778125, 0.42753314171155665, 0.4428531929033805, 0.4661832035911222, 0.4720455137926715, 0.496766723743933, 0.5050509103537271, 0.5270078856080865, 0.5473872645193004, 0.5569459652455575, 0.5796600115838687, 0.5875356156550416, 0.6061147268796726, 0.6305547447893398, 0.6406200740117949, 0.6566305394938076, 0.693308099879622, 0.704000910186169, 0.7167245112133032, 0.7234847634374618, 0.7539435072954089, 0.7702287313850589, 0.8004561409943179, 0.8066333545019096, 0.8149780722612512, 0.8212848138937983, 0.8390455437721485, 0.8706420672110646, 0.8917992849445093, 0.8978329687423149, 0.9226455087673376, 0.9270995008580138, 0.9458266676630526, 0.9687905925542548, 0.9850542500404122, 0.9937207283910537, 1.0321932324090188, 1.047243188019006, 1.0564011476330295, 1.0830567399365643, 1.097132267994993, 1.099805446042999, 1.1236630599230155, 1.1524060426588478, 1.1695823217415175, 1.1831163522208212, 1.2049289284518598, 1.2351960326281402, 1.2387830955622172, 1.2693723181259848, 1.3070088185684934, 1.3268233791430915, 1.3446903119170048, 1.351930932924152, 1.3720605501851304, 1.384898604268338, 1.429894466330166, 1.4497616867660508, 1.4807252322409898, 1.506100258343527, 1.527273016905896, 1.5377050437897, 1.554335886045926, 1.5677313585441193, 1.5899721024880356, 1.6734505432946907, 1.69011638966833, 1.733747972713644, 1.773123905378714, 1.7947111576318437, 1.8062319295874774, 1.8455328082081408, 1.925616726799956, 1.9626262531048766, -1.9689552571805402, -1.8790457078352625, -1.8376338254171494, -1.799823026215851, -1.7387634147541935, -1.734208627467471, -1.6855256890580133, -1.661282050575413, -1.6429180241606802, -1.6107462042806968, -1.5636457730207847, -1.536453139748177, -1.5297892325410276, -1.5218113901034904, -1.4772000740006035, -1.445612537967982, -1.4448935934825708, -1.4045487828726109, -1.3723530216629134, -1.3623822914497117, -1.354009342649843, -1.3446777714347216, -1.3042455426025854, -1.2991099742462089, -1.257307325402621, -1.2553996567288528, -1.242868849023238, -1.2318042592440668, -1.2220069687905872, -1.193221921340715, -1.1632300463696594, -1.136293694054517, -1.1154917906102662, -1.0973243163553033, -1.0695822298704236, -1.0544738878830617, -1.043826386714087, -1.03428161318849, -1.013325574491027, -1.0001754040124975, -0.9706496824961348, -0.9497749687886944, -0.9431314053554779, -0.9304619195905877, -0.9089811679254485, -0.8903003373117157, -0.8787634895079625, -0.8473477645193102, -0.8285365295879047, -0.8181153030017004, -0.8041267507566296, -0.7675199949919868, -0.75307776662368, -0.7405637199397297, -0.720622337486986, -0.7032938481577251, -0.6928756438360135, -0.6872809662861218, -0.6760550338450572, -0.6564644555168165, -0.6426679826074028, -0.6245384296851495, -0.607977891206693, -0.5828059515818528, -0.5727617420606138, -0.5665841562698712, -0.5504316614657443, -0.5422443411317275, -0.5251467261552539, -0.5207520751767625, -0.48843526641070667, -0.48366270410861845, -0.4594469308809691, -0.44288096996312076, -0.42333056430988286, -0.4039193805045114, -0.3768431982006931, -0.3452863253565851, -0.3376646898905597, -0.329071878453039, -0.32289772364457436, -0.29392200007153235, -0.2804159651679058, -0.26407314333420145, -0.2480865972180212, -0.22559410780692873, -0.20295530583995244, -0.2020669518620456, -0.19083146221626734, -0.1757193770074598, -0.15390448331960005, -0.14128577081594695, -0.12609325684822356, -0.11481179477059131, -0.10808274543089605, -0.10134828392537651, -0.07936940443968235, -0.0605011177523531, -0.037216823675309055, -0.03160380868361274, -0.025284516728793092, -0.006338502138890082, 0.02419339034705127, 0.06230420187512157, 0.0730781647844785, 0.0761787192426312, 0.09218267672996037, 0.1026948233072366, 0.11951746076157521, 0.13375013490548932, 0.1467281194361098, 0.1626635000511638, 0.19592725003326897, 0.20256413311541674, 0.2251527435436713, 0.24034623064142557, 0.2707583690539456, 0.2785553998406063, 0.2853114981339146, 0.3133994587963267, 0.3405248443425741, 0.3610302534362924, 0.37073757418439385, 0.3833436946419229, 0.4085279299395181, 0.4223183560504167, 0.4265798092601644, 0.4459167789511643, 0.4503237863673097, 0.4605835911255343, 0.4940547050995322, 0.5119391469529467, 0.5234730530689666, 0.5436133500176181, 0.5583979572009801, 0.573400945603298, 0.580425624866438, 0.5990002906081953, 0.6132819713121936, 0.6362363447513754, 0.640693702084262, 0.6532579977570677, 0.6828352190669229, 0.6852458193984988, 0.6929349534067257, 0.7118925033438206, 0.7447432735984447, 0.7593558091603746, 0.772629992125435, 0.7944918760595157, 0.807808472860516, 0.8281934313771626, 0.8354517246171665, 0.8459952246272106, 0.8833030514243212, 0.8962048773390948, 0.9221781264952182, 0.9300135573252382, 0.9538499179687057, 0.984390915129032, 0.9992543529594274, 1.0046008384914364, 1.0264687366952858, 1.0418632701343153, 1.0637817405519376, 1.0828895745275988, 1.1004299342372952, 1.1304022372160272, 1.139156824916889, 1.1559500397191038, 1.1817540866232041, 1.2186900535392748, 1.220769386865381, 1.2476285774333715, 1.2714989319547045, 1.2788251679233444, 1.292403873714452, 1.335455435997395, 1.3466015364533035, 1.36139914375315, 1.3918805173381343, 1.4182962181436634, 1.4330992922733456, 1.4525306493971692, 1.4662669520154306, 1.4887426953441847, 1.5307775021161876, 1.5588503700547331, 1.5816847190550862, 1.5915940654720353, 1.6341253675736935, 1.6705511088375358, 1.6913374116808293, 1.727658000283631, 1.7555578838282535, 1.8026190431033395, 1.8267833984715416, 1.8719045363440527, 1.9486103617872452, 1.9598667480796255, -1.9245117786543078, -1.8925355267817772, -1.8656492346738738, -1.8379778929653914, -1.815850919164804, -1.7294496612563988, -1.7003016864205245, -1.6578138703470715, -1.6571046471461646, -1.6179142216481748, -1.5947112518446316, -1.5566627889614137, -1.5303026353941878, -1.5113568190733162, -1.4707028364755164, -1.465446564034987, -1.4607357462531692, -1.4375572002985715, -1.417401216373402, -1.387639347560989, -1.335980885158122, -1.310633757953034, -1.2989268135360756, -1.2809373867254028, -1.2522116185957322, -1.2237667106348609, -1.2159166889936333, -1.207075183105587, -1.1957233206951725, -1.1768827272655458, -1.1570280399402875, -1.1438894660400127, -1.1250342406575256, -1.0900071462221754, -1.0788127127115992, -1.0621231586495814, -1.0463012690441085, -1.0370071087072907, -1.003221617481173, -0.9745508285088246, -0.9717694577293143, -0.9519307689439903, -0.9304732197907609, -0.9098134257141722, -0.9028073061525927, -0.8648270697418557, -0.8606368176028326, -0.8416765579919474, -0.824655961520299, -0.8118419948515302, -0.7947778073955418, -0.767525178609128, -0.7630411005728119, -0.7428124739185519, -0.7344950176749222, -0.7098724982333372, -0.6911856609361439, -0.6763067633845421, -0.6699276751858368, -0.6407995474244825, -0.6366893876466407, -0.6151975008880624, -0.595846218241886, -0.5914217087344382, -0.5673324979193775, -0.5423119773086647, -0.526229244688985, -0.5233757217979434, -0.5100603526279105, -0.4954642854508959, -0.48635825431799407, -0.47014265152789886, -0.45629921319894706, -0.42937710038824317, -0.4174259394810918, -0.39285797508776615, -0.37423693496556565, -0.35875780597050594, -0.3299068140136559, -0.3132662651343031, -0.30865018341818595, -0.29351795059505115, -0.2810955989265547, -0.265447530975697, -0.24951262583009945, -0.24723902894464356, -0.2312966850421337, -0.20725120647822304, -0.16707452866922967, -0.15677636602826078, -0.14827050358692276, -0.14070888425236142, -0.11426361280657141, -0.10459460983297253, -0.09338354848940268, -0.07711826621079351, -0.057271778325508386, -0.04286873639985318, -0.03227369036378587, -0.015793197303692372, -0.011547992155034128, 0.009465264088053758, 0.020931979680270284, 0.03896548120921549, 0.054525536802049336, 0.07297834133792257, 0.08902147579647084, 0.13253377912394868, 0.1362709332043867, 0.141480875158931, 0.15429159887478502, 0.15754321437853686, 0.17397803796676445, 0.19923307185390124, 0.2204770484243106, 0.2263499754938668, 0.2502630965670041, 0.2634379360031055, 0.29000645277327397, 0.3067700774398575, 0.3263837034791175, 0.3367341648098135, 0.36326049691108847, 0.36412708441560565, 0.3700211867683562, 0.3833519722876187, 0.40425461181313327, 0.414049097624153, 0.43659118488864235, 0.4412303225329877, 0.471935749571032, 0.4909955807779674, 0.5172330550491964, 0.5256420438525876, 0.5608579547063007, 0.5745646349928989, 0.5789478391220249, 0.591313430173218, 0.612619436482021, 0.6223540767815595, 0.6267430289575283, 0.6492526813231301, 0.6669641098585115, 0.6826906248905936, 0.7032755475645467, 0.7158783992982362, 0.7277842702961258, 0.7382682096844448, 0.7736286077735991, 0.790170725514366, 0.8057103511292395, 0.8198042656807997, 0.8340848222465191, 0.8554445977605089, 0.881012280426005, 0.8897700503434975, 0.9235488336496495, 0.9319102574739846, 0.9521159689851294, 0.9752193525911259, 0.9909733787421026, 0.9965311671925763, 1.0290092807481255, 1.0453867728995871, 1.0712400336268864, 1.0846961065757983, 1.1030744191665807, 1.1100255891589117, 1.1503768333072304, 1.1609050177244864, 1.1676150037892388, 1.2039148354814158, 1.2278760887712137, 1.245149793482302, 1.2727592816643463, 1.2838572808676703, 1.3053272135130767, 1.331850454889184, 1.3542726054468788, 1.3565279198612092, 1.3710091371721067, 1.4010854682793172, 1.4351598012603182, 1.4818129910217126, 1.5122362473925368, 1.5329367237641152, 1.549087042343283, 1.5726470044612835, 1.5941769452773087, 1.6039051746489486, 1.6547995577046113, 1.6663649026672747, 1.6793724227674984, 1.6936987211146737, 1.7435312226299566, 1.8006217614844529, 1.8605002939142807, 1.8918846375959064, 1.9150324042477807, 1.96784687803508]
xs = np.array(xs)
xs.sort()
fig, ax = plt.subplots(figsize=(12, 5))
q = 0.015
ys = [funq(q, x) for x in xs]
ax.plot(xs, ys)
ax.set_ylim(ymin=0)
ax.set_xlabel('x')
ax.set_ylabel('funq')
plt.show()

ERROR

Traceback (most recent call last):
  File "C:\Users\Parvathy\PycharmProjects\Hermite Polynomial\gaussian2p0.py", line 78, in <module>
ys = [funq(q, x) for x in xs]
  File "C:\Users\Parvathy\PycharmProjects\Hermite Polynomial\gaussian2p0.py", line 78, in <listcomp>
ys = [funq(q, x) for x in xs]
File "C:\Users\Parvathy\PycharmProjects\Hermite Polynomial\gaussian2p0.py", line 57, in funq
return (math.sqrt(1 - q) / 2 * math.pi * math.sqrt(4 - (1 - q) * (x ** 2))) * nprod(
ValueError: math domain error


Solution 1:[1]

You copied the formula, but you forgot to explain the part which describes the domain. From how the formula looks like, q should certainly be <= 1 (which would directly give an error for trying to square root a negative number), maybe it supposed to be between 0 and 1, with x between -2 and 2?

Also note that you forgot to put the multiplication signs. Without these, Python supposes you are doing function calls, leading to strange error messages.

To be able to call your function, it best to write it, well, as a function:

def funq(q, x):
    return (math.sqrt(1 - q) / 2 * math.pi * math.sqrt(4 - (1 - q) * (x ** 2))) * nprod(
        lambda i: (1 - q ** (i + 1))*((1 + q ** i) ** 2) - (1 - q)*(q ** i)*(x ** 2), [0, 100])

If the function wouldn't be using the multiprecision mpmath, it could be called with a complete numpy array of x values in one go. But, when mpmath functions are included, the function needs to be called on each x value, one by one. Beware that this can be extremely slow.

Here is some code that applies the function to 10 different q values, and shows them as a curve. As the x values aren't in order (there seem to be 3 leaps of 200 values), the values are sorted to prevent the plot going highwire.

import matplotlib.pyplot as plt
import math
from mpmath import nprod
import numpy as np

def funq(q, x):
    return (math.sqrt(1 - q) / 2 * math.pi * math.sqrt(4 - (1 - q) * (x ** 2))) * nprod(
        lambda i: (1 - q ** (i + 1))*((1 + q ** i) ** 2) - (1 - q)*(q ** i)*(x ** 2), [0, 100])

xs = [-1.9786357294030505,-1.8729683005605666,-1.8690079734953249,-1.7893930922097478,-1.7786223508087187,-1.7330418476321756,-1.7218150017905753,-1.7053215143651612,-1.6859860461491698,-1.6440572818865058,-1.6284242718994277,-1.594340198236287,-1.583713661880595,-1.5662028064425124,-1.511369193363463,-1.4959328789222448,-1.4756020410385255,-1.4362949249640893,-1.423699326374759,-1.3920503186588522,-1.3666704786700927,-1.3392600432337527,-1.3188944726286376,-1.300630969628771,-1.284216913905989,-1.2671896486219765,-1.2368473426034123,-1.235421991642431,-1.1970513167149672,-1.163387360445743,-1.1524460267982806,-1.13212800790605,-1.11682277889514,-1.0932584182021468,-1.0719251220099668,-1.0678870348976006,-1.0210296076133556,-1.0130488003608291,-0.9975858444089151,-0.9796452267641969,-0.9530125782990486,-0.9464384291595466,-0.9191313448853328,-0.9038898666356475,-0.8902743815564222,-0.8674005928510681,-0.8508650887302857,-0.8200469178891021,-0.8085708326297844,-0.7881170124056511,-0.7799411570886873,-0.7661606085504135,-0.7618458977422593,-0.7492332851473245,-0.7373083334809616,-0.719374597403646,-0.7026302150707191,-0.6729458730969575,-0.6559214240063347,-0.6493288264029489,-0.6218035549315963,-0.607466462637045,-0.596294879772371,-0.5713878489863752,-0.5598867615279391,-0.5572092841273873,-0.5273247323025781,-0.5221465145961504,-0.4925721990514733,-0.48310483493375744,-0.4718028670160281,-0.44426669977293703,-0.4386304188536966,-0.43405364241292016,-0.4021647180497939,-0.3927630747654775,-0.3707640646729126,-0.35506873216266965,-0.34834585664141654,-0.3319465767329759,-0.2894674105765397,-0.2817473493386308,-0.26957856656820584,-0.2615569395897469,-0.25386346475088906,-0.23528915363262143,-0.21698584251388872,-0.1933748674795559,-0.18559018928903234,-0.17160387866256502,-0.1687830111167416,-0.14974728885496646,-0.13804745514819466,-0.11923132937556802,-0.10176330992119202,-0.08467961756036736,-0.0635710853983301,-0.04620384807512924,-0.023706228233325653,-0.020329108587452387,-0.004536805620385409,0.01049134854325218,0.04292771525256894,0.06067759178398313,0.06822867908723125,0.09118306217222992,0.10708472302097773,0.12057759872860745,0.13207640947677135,0.15166551213353896,0.17118988666950177,0.17713745442040899,0.19965260497566134,0.2134119323494147,0.23784494435362605,0.2551296841720161,0.26428140746568396,0.26853941563033434,0.2883002215813374,0.3088450422437123,0.32659857314747376,0.35028020322764974,0.35652392405534983,0.37353733908535114,0.38093124895960145,0.3888334202882138,0.43580283094851185,0.4471450889908507,0.46585500567028143,0.5014418423782477,0.5051994192994206,0.5312947926610357,0.5495070698301275,0.5503358521115466,0.5567675709547716,0.593262743016464,0.5957398500355201,0.6148641411496494,0.6215789147290754,0.6262076647002017,0.6563209774380261,0.6732407668582557,0.694602036698193,0.7105886846018437,0.7246384345455785,0.7440648676491575,0.7576474680600296,0.7809521435309291,0.7907796476189285,0.7974666399351398,0.830233890957038,0.8583238856991258,0.8753678555773454,0.8834793982320464,0.9079280272571449,0.9095178763387498,0.9216786507153699,0.9361529250822589,0.9517403164092609,0.9707510788524722,0.9813086631062877,1.0009213904099536,1.0271197471735438,1.0454782328986996,1.0589826548690298,1.0738076787890236,1.0939970755818516,1.108844856545789,1.1242177261974418,1.1469475819883208,1.1569086631966876,1.184912907917583,1.206486214117146,1.2187025753360223,1.2669839237894613,1.2846273014950762,1.3182316671735366,1.32732883588292,1.3453440614407257,1.3686243254134494,1.3707222594460755,1.4013900463539046,1.4053423560030363,1.4425665235329186,1.4682651589031035,1.4833174961903184,1.510306637513224,1.5394845108942132,1.552577965032721,1.570537066079267,1.6046955859559133,1.6341308355418969,1.6525106440774544,1.6791516946558083,1.7464079020909997,1.776987500944659,1.8163870734766445,1.8599053537185501,1.876231778796384,1.9458011294201891,-1.9512196654751857,-1.8829812085480147,-1.8576710431594026,-1.7962607878829076,-1.7906921105373508,-1.7807662079136575,-1.7243537674252296,-1.6653760064322933,-1.6247791399291813,-1.6131800223977202,-1.5992690882006375,-1.5711596720979557,-1.5423532598624516,-1.5366416410035018,-1.504960954218726,-1.4924796299349394,-1.4651134679176212,-1.454086257567312,-1.435312299789483,-1.3900656838493024,-1.3710456440546588,-1.3289367992734276,-1.3175853505277841,-1.2935618896837286,-1.2911125035321889,-1.2705424625860116,-1.2495382702510687,-1.1913798629046468,-1.1838747404652799,-1.1545896195973815,-1.1411111303499946,-1.1295376236771988,-1.1133537812338583,-1.088174769710425,-1.0635278526778984,-1.0476645832032065,-1.0391589671067623,-1.024214524630082,-1.0172424281544814,-1.000235923512485,-0.9508581215025034,-0.9398414654598437,-0.9194964159277919,-0.9134585512802674,-0.8934873866985384,-0.8814068284436899,-0.8780235651897508,-0.8606464532377365,-0.8356762831449271,-0.8187239412996997,-0.7854978612688941,-0.7828386290808195,-0.7690085876655378,-0.7421029961018879,-0.7311170128877692,-0.7264957952911963,-0.7026853588698583,-0.6818444893142,-0.6721154623517708,-0.657078101256421,-0.6452274971677785,-0.6300075175829053,-0.6242267077379532,-0.5721969221810158,-0.5662035998641474,-0.5479259590977337,-0.5314602882649556,-0.5115321242783482,-0.4983577363159967,-0.4855819569700855,-0.48049012538376157,-0.4705180532386064,-0.44026650027082903,-0.435885161812978,-0.41180385376632433,-0.4017315540454998,-0.38747272372482705,-0.3759596980455016,-0.35489972421863536,-0.32461587122331836,-0.3098980922570402,-0.30758164674256944,-0.2822384073202352,-0.2656467415193894,-0.23710268441490095,-0.21537502792932678,-0.20653737924922524,-0.18828314947264962,-0.17863010696438195,-0.16565457795453492,-0.12727343410031944,-0.12125519683707242,-0.11572044525666327,-0.10039113723818469,-0.08215421819779734,-0.07462269279234593,-0.04733697243495624,-0.03902256229136341,-0.015004607861846557,0.0023866686310914987,0.016905251620411982,0.03633573190335912,0.04513078233697063,0.06251138849975102,0.07288973913733753,0.08478810329844741,0.11787454997841305,0.1278262739774144,0.13199265819356742,0.15351161957574785,0.16423257996738377,0.1902837083202764,0.19444594881545285,0.22069844718453066,0.2342673779194781,0.2432229363065642,0.25656196352730404,0.2748011668035119,0.29476629829733686,0.3152508033830516,0.3390860976090646,0.34529893266442696,0.3509103613720826,0.3567298461252108,0.38524111994610016,0.3984287333260647,0.4215287545280487,0.42624162956106615,0.44342322691656655,0.46815779770191773,0.4826276751528516,0.48736326010167075,0.5270847559132682,0.535137069854498,0.5597852966648887,0.5636516152920249,0.5891497307041484,0.60387281563308,0.6122258162432502,0.622420591346527,0.6425499822557241,0.6470898125562051,0.6749954254362208,0.6906985075158013,0.7111208770900466,0.7259954339219178,0.7353307943827243,0.7417959844098685,0.7773497993802436,0.804518457940357,0.8125382416356816,0.8357005127959714,0.8497608874587113,0.877727667464255,0.8991535828185762,0.9028047774076086,0.9201981762415962,0.9347787953496884,0.9431830927841084,0.9734287272500868,0.9853110402483333,1.0185984653893043,1.0330876627603427,1.0440564887048558,1.0678777326525455,1.0799832507864535,1.097210140121914,1.1151293673809275,1.1476624065213055,1.171885726256288,1.1945489498466135,1.2042165808436103,1.223472010303144,1.2428769260838406,1.2722914813843251,1.2861144376992115,1.2911038312520828,1.324115710357473,1.3445670941521717,1.3620424936417799,1.4032442887281618,1.4262897158434138,1.43564934224993,1.4450583046652594,1.4898334852707136,1.4927707935477652,1.520810157082525,1.5367811961409679,1.552026804662004,1.6053917806651012,1.6402918617256708,1.6761280178591647,1.6923263924096053,1.6986424433215552,1.710664592743046,1.7416599676870563,1.7963775987522719,1.8268791635346637,1.8751778855549728,1.981682354314677,-1.9720118878290451,-1.939537662618986,-1.8918865724553584,-1.829877703387402,-1.7431576040339352,-1.7306999822153466,-1.725962554470109,-1.6955865422202412,-1.6874714573128762,-1.6564596133447511,-1.6287728876605636,-1.5687299291185692,-1.5500896765665118,-1.5041200129610381,-1.48815635666796,-1.4784514793204815,-1.4631104994968076,-1.4320533545530292,-1.385389061180228,-1.3756431584361017,-1.3407874937789346,-1.33089680314093,-1.3219489713300154,-1.3113647860494129,-1.2820497525693115,-1.2651759076742832,-1.2509187718941184,-1.2152994934030503,-1.1970958921293093,-1.1722115000513733,-1.1389481216517459,-1.124402448818879,-1.1108170242758857,-1.0910330538373234,-1.0852000040036263,-1.048868398984999,-1.037936575357004,-1.0184332805190326,-1.0040975836663302,-0.9908621277308675,-0.9808689639791376,-0.9576203771413969,-0.9383574827273514,-0.9241390631756303,-0.9006653561377413,-0.8882296350415737,-0.863499813984361,-0.8629738297540374,-0.832724843648317,-0.7954918552313025,-0.7841259500061021,-0.7629012968173354,-0.7396302666131434,-0.7325973549311713,-0.7172558883528847,-0.7035977546489376,-0.681718470024906,-0.6655340199032569,-0.6450940866579479,-0.6359437971536883,-0.6212006386783995,-0.5998238924801844,-0.5968507213695506,-0.5858328985138637,-0.5672812914958087,-0.5556718857232429,-0.527397662332296,-0.5054835290093602,-0.5002298161775866,-0.4819563855253971,-0.46731198577965777,-0.44735410123493013,-0.4359610933335695,-0.4267388065351008,-0.4100386108705584,-0.3777458706265244,-0.3660746444937139,-0.3434582909646087,-0.3251968641014367,-0.3209015434690784,-0.3129616372834409,-0.28342622089649283,-0.2711549862793822,-0.26422374179577857,-0.2572621692963007,-0.23383676389842692,-0.22255734057700996,-0.20332035913196134,-0.17902737216651185,-0.16350716516250746,-0.14985383910405983,-0.14177492514618775,-0.11738154792002622,-0.1080138817434151,-0.09178597250488336,-0.07086476635560314,-0.05080997310184168,-0.034820014063490716,-0.018611211144636736,0.0028377929901877304,0.0075485897441987596,0.036178856878983506,0.041080399335373295,0.05476190645467531,0.06949732553710167,0.09564050628836183,0.10461640687798392,0.1178735335311192,0.12380142675426353,0.16284867195120775,0.16645355064195846,0.17563199784704414,0.1902197422150256,0.20752052833888784,0.22138309372887924,0.22636331368429083,0.24261264064241983,0.2556095107016821,0.28522514338235855,0.2982192111742722,0.31423811916673333,0.33525714606469353,0.3627991090366422,0.37870349174770274,0.38889078665045085,0.4005697670980977,0.4072415222178772,0.4309877730560121,0.4566410063350807,0.47269491516977874,0.4884074671976161,0.48963567032081695,0.5061463389521641,0.5137757976539188,0.5320778362867615,0.5663552383156409,0.5913098355667258,0.6001420620215526,0.6062502577529896,0.6228155322803758,0.6566945705929244,0.6701040912330436,0.6856301582312107,0.6975590484067273,0.7140459359536921,0.7337194009538845,0.74478975523831,0.7645867010719698,0.7750346797057056,0.7865373723034326,0.800430103974259,0.8389871896871637,0.8568161836747437,0.8753518460262228,0.8845545677139671,0.8960922464554294,0.9031465082720954,0.921694852314396,0.9520374908991852,0.9529355500377263,1.0024617265875448,1.0031624720038754,1.029123254557672,1.0502250251123864,1.0830245555662672,1.091864291075987,1.1164219122856645,1.1246840470826236,1.153128780982803,1.1587867797247688,1.1817350579984447,1.1891237906787095,1.2200203479054452,1.2401409256884295,1.2556173762573795,1.2784656407350519,1.3029409978443105,1.3150519586420686,1.3426738291642524,1.3550941015704991,1.3801928137282742,1.3880017332550125,1.4117247676640234,1.4256158120335196,1.4976831924466858,1.504045440500496,1.5156581232969064,1.5475051109944318,1.5991000053604998,1.6128701172592261,1.640789269860826,1.6547622923153782,1.6899389055622647,1.701898602409724,1.7429636984357195,1.783109902918529,1.8224037985924213,1.8651023143071406,1.882137792076811,1.9153278741127084]
xs = np.array(xs)
xs.sort()
fig, ax = plt.subplots(figsize=(12, 5))
for q in np.arange(0, 1, 0.1):
    ys = [funq(q, x) for x in xs]
    ax.plot(xs, ys, label=f'q={q:.1f}')
ax.set_ylim(ymin=0)
ax.set_xlabel('x')
ax.set_ylabel('funq')
ax.legend()
plt.show()

plotting funq as curves

PS: For a single value of q, you could write:

q = 0.37
ys = [funq(q, x) for x in xs]
ax.plot(xs, ys)

Here xs is a list of x values, and ys a list of corresponding y values. Matplotlib will connect these values one-by-one to show a curve. Numpy is Python's superpower library to easily and fastly work with lists (or matrices or n-D arrays) of numbers. For an introduction to numpy, maybe this tutorial could be a start.

The label= parameter to plot are meant for the label to put into the legend. f'q={q:.1f}' is Python's new way to format strings.

As you seem to be very new to Python, a tutorial (e.g. this one) could be a start.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1