如何绘制非线性曲线拟合并获得拟合参数误差函数加高斯函数?

问题描述

我有一个二维 vloc(r) 数组,其中 (r=24x24) 数组。我想拟合表达式的曲线 V_loc(r) =−(Z/r)∗erf(r/R) +∑A_i∗exp(−α_i*r^2) 这里(∑ i =1,2 or many)

这里,我知道参数 Z、R 和 V_loc。

V_loc(24,24)=array([-0.647748928690326,-0.666253391251891,-0.671970718862185,-0.675054301855004,-0.733722401168183,-0.834278689600485,-0.954365911028046,-1.09827769756813,-1.25168355475072,-1.38535988817219,-1.52139555327104,-1.61649171748213,-1.65412243215032,-1.61607380026939,-1.52202829447006,-1.38634280015122,-1.25063875528266,-1.09659582774049,-0.956297244425273,-0.835652928778868,-0.731889667109413,-0.674815763825111,-0.671794051537137,-0.66628062625935
-0.666280626259346,-0.664985176646352,-0.670474325184302,-0.670336750188364,-0.66914481278236,-0.708145050866414,-0.799547602921493,-0.882152589153673,-0.983738532734582,-1.09841184206199,-1.19642460153332,-1.26610016769435,-1.3042095484428,-1.30365232528197,-1.26704157064167,-1.19586788213035,-1.09704802010894,-0.985605928204154,-0.882733349167268,-0.797635388686604,-0.707441293358868,-0.670816989473527,-0.67048098990176,-0.670502435122069
-0.671794051537126,-0.681930059696877,-0.672802331215178,-0.6700870937756,-0.663226482921177,-0.666196809059399,-0.698545735541464,-0.745273674963785,-0.813008352927148,-0.879926774430465,-0.943235744524842,-1.00732418065168,-1.04524634933882,-1.06319717423037,-1.04526338340485,-1.00544106522118,-0.94460610140007,-0.880295726886094,-0.811026850305662,-0.744714244119287,-0.700382848097282,-0.666890346336686,-0.660915390837294,-0.670480989901759
-0.67481576382511,-0.685113278917253,-0.684444399882546,-0.674013357237871,-0.668938526286259,-0.666474244257453,-0.70083748909536,-0.701149323998348,-0.701235494648126,-0.733273540348833,-0.780995807840454,-0.821295995374534,-0.850291648441264,-0.865901604843165,-0.866242423546694,-0.851347087521381,-0.821872851500211,-0.779894678527035,-0.732479443843238,-0.70258189319618,-0.701596943511641,-0.698403574698121,-0.666890346336681,-0.670816989473532
-0.731889667109411,-0.754178558521725,-0.763486082196503,-0.753417124698051,-0.733949369429597,-0.708267223379659,-0.699157152689423,-0.700634456288028,-0.705323858741952,-0.688856340409359,-0.671189889534928,-0.68595367182729,-0.702690968172468,-0.723266372453558,-0.723711522449406,-0.722444391949465,-0.702099690880754,-0.685306958218864,-0.673241231650128,-0.688903373509297,-0.702690661354643,-0.701596943511647,-0.700382848097284,-0.707441293358862
-0.835652928778866,-0.864240018976758,-0.877489413321044,-0.878414199343314,-0.862899628328017,-0.834979590351599,-0.799622114310811,-0.745001996260995,-0.700777525809392,-0.688221999058378,-0.67842117232472,-0.648979445757785,-0.622146559295344,-0.61326030543885,-0.614749448923311,-0.616171179421897,-0.613639282550223,-0.623134858964965,-0.649808971034993,-0.676792692256437,-0.688903373509305,-0.702581893196148,-0.744714244119284,-0.797635388686597
-0.956297244425282,-1.01434138341385,-1.05282814738939,-1.0704834371676,-1.05391562738596,-1.01731741649037,-0.953549442250269,-0.880535922506445,-0.813038040998519,-0.732547831662121,-0.672241242197546,-0.64847707572502,-0.61984160354363,-0.589425307374169,-0.558277145916163,-0.548268501134217,-0.556822531198883,-0.58862799127772,-0.618445985442526,-0.649808971035011,-0.673241231650166,-0.811026850305632,-0.882733349167267
-1.09659582774051,-1.19675376808398,-1.26809446740913,-1.30689047720045,-1.30508014475881,-1.26584784428737,-1.19663877985691,-1.0994906720431,-0.984796511822105,-0.878346079397519,-0.782719071080839,-0.685420063700898,-0.621703529786361,-0.588442128198876,-0.565648131431237,-0.550662905670033,-0.550199154132898,-0.567727292668732,-0.588627991277734,-0.623134858964955,-0.685306958218871,-0.779894678527056,-0.880295726886145,-0.985605928204153
-1.25063875528266,-1.39010825445076,-1.52067899064287,-1.61494962768242,-1.64709466481185,-1.61810280935684,-1.51910647605119,-1.38985445172163,-1.25182095349429,-1.09852024318615,-0.943900848797394,-0.820803614239613,-0.703836674412839,-0.614343442957325,-0.559433522969422,-0.55025407910723,-0.557894225239074,-0.550199154132854,-0.556822531198932,-0.61363928255024,-0.702099690880748,-0.821872851500224,-0.94460610140008,-1.09704802010894
-1.38634280015123,-1.61523849408241,-1.82768494082505,-1.94417271474397,-1.98193325758626,-1.97919588740633,-1.9437352987391,-1.83021296590881,-1.61477589141267,-1.3871730473259,-1.19816061895598,-1.00549421521211,-0.851670495905685,-0.722651524769659,-0.615345854202384,-0.548159887654332,-0.550254079107251,-0.550662905670029,-0.548268501134212,-0.61617117942188,-0.722444391949416,-0.851347087521386,-1.00544106522117,-1.19586788213035
-1.52202829447006,-1.83212978050732,-1.99541057510026,-1.95788385213493,-1.87355071633494,-1.84425664901171,-1.87504709789492,-1.95744325239706,-1.99554810882119,-1.83425019114304,-1.52079301286605,-1.26591775505592,-1.04611695716278,-0.86534962871365,-0.724129178227444,-0.615345854202322,-0.559433522969348,-0.565648131431199,-0.558277145916142,-0.614749448923277,-0.723711522449429,-0.866242423546728,-1.04526338340482,-1.26704157064168
-1.61607380026939,-1.9505076345923,-1.96188041368445,-1.79048761871717,-1.76505293397301,-1.82416558966659,-1.82597995827808,-1.76416682631602,-1.79107677399806,-1.95945917213438,-1.95095766740246,-1.62034745152298,-1.30397101818407,-1.06168508708651,-0.865349628713648,-0.722651524769672,-0.614343442957276,-0.588442128198826,-0.589425307374181,-0.613260305438875,-0.723266372453566,-0.865901604843173,-1.06319717423032,-1.30365232528196
-1.65412243215029,-1.98912882116151,-1.8829098755764,-1.76669767310343,-2.06654701837695,-2.51332203109434,-2.71084099790913,-2.51060675180526,-2.067188008962,-1.76853028174023,-1.88225521945414,-1.98865960749252,-1.65348244724335,-1.30397101818408,-1.04611695716277,-0.703836674412827,-0.621703529786297,-0.619841603543645,-0.622146559295345,-0.702690968172451,-0.85029164844121,-1.04524634933876,-1.30420954844281
-1.6164917174821,-1.98817711746182,-1.85199119938161,-1.83119071557126,-2.51749752367917,-3.47079958422506,-4.12716551986336,-4.12995490020073,-3.47268987122055,-2.51364034006852,-1.83049078291028,-1.85428959418007,-1.98865960749251,-1.2659177550559,-1.00549421521213,-0.820803614239643,-0.685420063700933,-0.648477075725004,-0.64897944575781,-0.685953671827261,-0.821295995374578,-1.00732418065166,-1.26610016769437
-1.52139555327103,-1.95136648210607,-1.88319636251561,-1.83145913434106,-2.71432770295669,-4.13066798104772,-5.33649014490812,-5.78177539508871,-5.3335748222283,-4.13189744369877,-2.71852547702655,-1.83049078291029,-1.88225521945413,-1.9509576674025,-1.52079301286602,-1.19816061895599,-0.943900848797402,-0.782719071080867,-0.672241242197509,-0.678421172324714,-0.671189889534961,-0.780995807840438,-0.943235744524825,-1.1964246015333
-1.38535988817218,-1.83352637566289,-1.95927499858789,-1.76842060454195,-2.51519079062503,-4.13275238289122,-5.78304570303744,-6.74297885832179,-6.7444126404872,-5.78379815036881,-1.76853028174021,-1.83425019114302,-1.38717304732588,-1.09852024318618,-0.878346079397497,-0.73254783166217,-0.688221999058384,-0.688856340409394,-0.733273540348856,-0.879926774430471,-1.098411842062
-1.25168355475069,-1.61421794515184,-1.99617749914048,-1.79155322706376,-2.06557326816572,-3.47261245916264,-5.33336939783356,-6.74424833279801,-7.26812928127244,-6.74441264048722,-3.47268987122059,-2.06718800896197,-1.79107677399805,-1.99554810882117,-1.61477589141265,-1.25182095349431,-0.984796511822061,-0.813038040998484,-0.700777525809429,-0.705323858741882,-0.701235494648129,-0.81300835292716,-0.983738532734589
-1.09827769756814,-1.38874772611063,-1.82972812229922,-1.9557707371466,-1.76579203675006,-2.51177317731124,-4.12895672526661,-5.78319949838266,-5.7817753950887,-4.12995490020085,-1.76416682631601,-1.83021296590879,-1.38985445172162,-1.09949067204312,-0.880535922506419,-0.745001996261012,-0.700634456288014,-0.701149323998364,-0.745273674963811,-0.882152589153672
-0.954365911028054,-1.19750227388931,-1.51997346736235,-1.94416933311173,-1.87481250197338,-1.82383305092576,-2.71221612437119,-5.33336939783355,-4.12716551986346,-2.71084099790915,-1.82597995827804,-1.8750470978949,-1.51910647605118,-1.1966387798569,-0.953549442250289,-0.799622114310823,-0.699157152689407,-0.70083748909535,-0.69854573554146,-0.799547602921491
-0.834278689600482,-1.0167098111582,-1.26607329958114,-1.61706531098553,-1.97982504638627,-1.84537984503426,-1.82383305092577,-3.47261245916265,-4.13275238289129,-4.1306679810478,-3.47079958422508,-1.82416558966657,-1.8442566490117,-1.61810280935687,-1.01731741649036,-0.834979590351593,-0.708267223379643,-0.666474244257439,-0.666196809059393,-0.708145050866409
-0.733722401168182,-0.862932314274031,-1.05333831172386,-1.30612786766349,-1.64726399950066,-1.76579203675004,-2.0655732681657,-2.51519079062501,-2.71432770295671,-2.51749752367914,-2.06654701837692,-1.76505293397302,-1.87355071633491,-1.98193325758624,-1.64709466481183,-1.3050801447588,-1.05391562738598,-0.862899628328024,-0.733949369429606,-0.668938526286273,-0.663226482921188,-0.669144812782354
-0.675054301855009,-0.753324891649797,-0.878439212581839,-1.07019812732474,-1.3061278676635,-1.94416933311175,-1.95577073714661,-1.76842060454194,-1.76669767310342,-1.79048761871718,-1.95788385213491,-1.94417271474398,-1.61494962768243,-1.07048343716759,-0.8784141993433,-0.753417124698045,-0.674013357237853,-0.670087093775598,-0.670336750188349
-0.671970718862185,-0.684889039436355,-0.763475855910964,-0.878439212581842,-1.05333831172384,-1.26607329958113,-1.82972812229923,-1.99617749914049,-1.88319636251562,-1.85199119938165,-1.88290987557641,-1.96188041368446,-1.99541057510025,-1.52067899064285,-1.0528281473894,-0.877489413321043,-0.76348608219651,-0.684444399882554,-0.672802331215185,-0.67047432518431
-0.666253391251885,-0.681812206174578,-0.684889039436354,-0.7533248916498,-0.862932314274034,-1.01670981115821,-1.61421794515187,-1.8335263756629,-1.95136648210608,-1.98817711746181,-1.95050763459231,-1.83212978050733,-1.19675376808399,-0.864240018976749,-0.75417855852172,-0.685113278917249,-0.681930059696884,-0.664985176646346])

我使用 scipy python 代码来适应如下

import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
    
# Function to calculate  with fitting parameter constants A and alp
def func(Z,R,r,A,alp):
    global Z,R
    return -(Z/R)*erf(r/R) + A*np.exp(-(alP**2)*r**2)

# Fit the dummy  data
Z=74
R =0.5
pars,cov = curve_fit(f=func,xdata,ydata,p0=[0,0],bounds=(-np.inf,np.inf))
    
    
####  I  DO NOT KNow HOW TO USE xdata and ydata
    
A,alp = pars
    
# print the fit results
print("A:%.2f"%(A))
print("alp:%.2f"%(alp))

我是曲线拟合和编程的初学者。我将不胜感激解决这个问题。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)