资源描述:
《插值法VB源程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、第四章插值方法VB一、线性插值应用实例VB1已知:169的平方根为13,196的平方根为14,编程求175的平方根。PrivateSubCommand1_click()Dimx(1To2),y(1To2)AsSinglex(1)=169:y(1)=13x(2)=196:y(2)=14x0=175y0=F(x,y,x0)a=Format$(y0,"###.##")Text1.Text="y0="&Str$(a)EndSubPrivateFunctionF(x,y,x0)F=y(1)+(y(2)-y(1))/(x
2、(2)-x(1))*(x0-x(1))EndFunction线性插值应用实例VB2n已知水的温度与密度和关系如下:0.9956460.9970440.9982030.990990.997000.999965密度/(g/ml)30.025.020.015.010.05.0温度/0C试编程计算温度为6、13、16、19、23、26oC时的密度。PrivateSubCommand1_click()N=6X=Array(0,5,10,15,20,25,30)Y=Array(0,0.999965,0.9997,0.99
3、9099,0.998203,0.997044,0.995646)xc=Array(0,6,13,16,19,23,26)List1.AddItem"x0"&"y0"ForI=1To6X0=xc(I)Y0=f(N,X,Y,X0)List1.AddItemStr$(X0)&Str$(Y0)NextIEndSubPrivateFunctionf(N,X,Y,X0)ForI=1ToNIfX0<=X(I)ThenW=IExitForEndIfNextIW=W-1IfW<=1ThenW=1:EndIfIfW>=NThen
4、W=N-1:EndIff=Y(W)+(Y(W+1)-Y(W))/(X(W+1)-X(W))*(X0-X(W))EndFunction二、拉格朗日三点插值实例例:实验测得25OC乙醇溶液的平均摩尔体积v与乙醇的摩尔分数xi的关系数据如下表。试编程求摩尔数xi为0.3时的乙醇溶液的平均体积v。0.24240.20680.17390.14350.11530.0891xi26.9525.5724.3223.1822.1621.22v0.47710.42070.36970.32340.2811xi36.3734.073
5、2.0130.1528.47vVB清单DimX,vPrivateSubCommand1_click()N=75X=Array(0,8,7,6,5,4.8,4.6,4.4,4.4,4.0,3.8,3.6,3.4,3.2,3.0,2.9,2.8,2.7,2.6,2.5,2.4,2.00,1.95,1.90,1.85,1.80,1.75,1.70,1.68,1.66,1.64,1.62,1.60,1.58,1.56,1.54,1.52,1.50,1.48,1.46,1.44,1.42,1.40,1.39,1.38,
6、1.37,1.36,1.35,1.34,1.33,1.32,1.31,1.30,1.29,1.28,1.27,1.26,1.25,1.24,1.23,1.22,1.21,1.20,1.19,1.18,1.17,1.16,1.15,1.14,1.13,1.12,1.11,1.10,1.09,1.08,1.07)v=Array(0,0.24978,0.24970,0.24958,0.24937,0.24931,0.24925,0.24917,0.24907,0.24896,0.24883,0.24868,0.24
7、849,0.24825,0.24795,0.24778,0.24758,0.24735,0.24708,0.24678,0.24643,0.24421,0.24380,0.24333,0.24281,0.24222,0.24156,0.24081,0.24048,0.24013,0.23977,0.23938,0.23897,0.23854,0.23807,0.23758,0.23705,0.23648,0.23588,0.23524,0.23455,0.23381,0.23301,0.23259,0.232
8、15,0.23170,0.23123,0.23073,0.23022,0.22968,0.22912,0.22854,0.22893,0.22729,0.22662,0.22593,0.22520,0.22443,0.22361,0.22275,0.22185,0.22090,0.21990,0.21884,0.21771,0.21652,0.21526,0.21390,0.21245,0.2109