数值分析实验报告(一)2016级数学基地班尹烁翔320160928411一、问题重述:hamming级数求和二、问题分析级数为∑1k(k+x)∞k=1易知当X=1时,φ(1)=1我们可以考虑这个新级数:φ(x)−φ(1)用这个级数可以使精度更高,误差更小且迭代次数变少。
通分易得:φ(x)−φ(1)=1k(k+x)−1k(k+1)=1−xk(k+x)(k+1)我们还可以继续算得φ(2)及φ(x)−φ(2)这样精度会继续提高,且迭代次数也会减少。
下面考虑误差:由公式可得∑1−xk(k+x)(k+1)∞k=1<1k3<∫1k3∞n−1<10−10要把误差控制在范围内,需要k即迭代次数至少70001次。
三、算法实现:#include<iostream>#include<iomanip>>using namespace std;int main(){double sum;//sum为级数和double x;//x为代入的自变量int k=1;//k为迭代次数for (x=0; x<=10; x=x+0.1)//对0到10以内进行迭代运算,每次加0.1{sum=0;//每迭代完一个x,级数归零for (k=1; k<=70001; k++)//固定x并对k进行运算{sum=sum+1/(k*(k+x)*(k+1));}sum=(1-x)*sum+1.0;cout<<setiosflags(ios::fixed)<<" "<<setprecision(1)<<x;cout<<setiosflags(ios::fixed)<<" "<<setprecision(10)<<sum<<endl;}for (x=11; x<=290; x++)//对11到290以内进行迭代运算,每次加1{sum=0;for (k=1; k<=70001; k++)//固定x{sum=sum+1/(k*(k+x)*(k+1));}sum=(1-x)*sum+1.0;cout<<setiosflags(ios::fixed)<<" "<<setprecision(1)<<x;cout<<setiosflags(ios::fixed)<<" "<<setprecision(10)<<sum<<endl;}for (x=290; x<=300; x=x+0.1)//对290.1到300以内进行迭代运算,每次加0.1 {sum=0;for (k=1; k<=70001; k++)//固定x{sum=sum+1/(k*(k+x)*(k+1));}sum=(1-x)*sum+1.0;cout<<setiosflags(ios::fixed)<<" "<<setprecision(1)<<x;cout<<setiosflags(ios::fixed)<<" "<<setprecision(10)<<sum<<endl;}return 0;}四、数据结果:0.0 1.6449340667 0.1 1.5346072448 0.2 1.4408788415 0.3 1.3600825867 0.4 1.2895778007 0.5 1.2274112777 0.6 1.1721051961 0.7 1.1225193425 0.8 1.07775887270.9 1.03711091781.0 1.0000000000 1.1 0.9659560305 1.2 0.9345909181 1.3 0.9055811887 1.4 0.8786548819 1.5 0.853******* 1.6 0.8301644486 1.7 0.8082346082 1.8 0.78764591881.9 0.76827137672.0 0.7500000000 2.1 0.7327343381 2.2 0.7163884348 2.3 0.7008861540 2.4 0.6861597923 2.5 0.6721489224 2.6 0.6587994241 2.7 0.6460626684 2.8 0.63389482552.9 0.62225627673.0 0.6111111113 3.1 0.6004266954 3.2 0.5901732990 3.3 0.5803237751 3.4 0.5708532792 3.5 0.5617390263 3.6 0.5529600781 3.7 0.5444971556 3.8 0.53633247553.9 0.52844960504.0 0.5208333336 4.1 0.5134695598 4.2 0.5063451894 4.3 0.49944804604.4 0.49276679034.5 0.48629084784.6 0.48001034484.7 0.47391604974.8 0.46799932104.9 0.46225205975.0 0.45666666715.1 0.45123600545.2 0.44595336325.3 0.44081242345.4 0.43580723395.5 0.43093218145.6 0.42618196715.7 0.42155158445.8 0.41703629915.9 0.41263163046.0 0.40833333386.1 0.40413738606.2 0.40003996986.3 0.39603746096.4 0.39212641636.5 0.38830356206.6 0.38456578316.7 0.38091011406.8 0.37733372946.9 0.37383393577.0 0.37040816397.1 0.36705396157.2 0.36376898657.3 0.36055100097.4 0.35739786507.5 0.35430753177.6 0.35127804177.7 0.34830751887.8 0.34539416537.9 0.34253625788.0 0.33973214368.1 0.33698023688.2 0.33427901518.3 0.33162701648.4 0.32902283598.5 0.32646512338.6 0.32395258008.7 0.32148395698.8 0.31905805168.9 0.31667370669.0 0.31432980689.1 0.31202527809.2 0.30975908459.3 0.30753022799.4 0.30533774499.5 0.30318070609.6 0.30105821429.7 0.29896940319.8 0.29691343609.9 0.294889504210.0 0.292896826311.0 0.274534305112.0 0.258600891013.0 0.244625674714.0 0.232254453215.0 0.221215267616.0 0.211295563617.0 0.202326620618.0 0.194172672719.0 0.186723141720.0 0.179886984821.0 0.173588511822.0 0.167764240823.0 0.162360502724.0 0.157331593125.0 0.152638329626.0 0.148246914727.0 0.144128030628.0 0.140256111329.0 0.136608754530.0 0.133166240731.0 0.129911138432.0 0.126827978033.0 0.123902979834.0 0.121123826635.0 0.118479472636.0 0.115959981337.0 0.113556388138.0 0.111260583139.0 0.109065210040.0 0.106963580041.0 0.104949596342.0 0.103017690143.0 0.101162762944.0 0.099380138345.0 0.097665518246.0 0.096014944747.0 0.094424767348.0 0.092891612649.0 0.091412358750.0 0.089984111851.0 0.088604185152.0 0.087270081253.0 0.085979474654.0 0.084730197955.0 0.083520227556.0 0.082347672757.0 0.081210763958.0 0.080107843659.0 0.079037357560.0 0.077997846261.0 0.076987938262.0 0.076006343163.0 0.075051846164.0 0.074123301865.0 0.073219629966.0 0.072339810267.0 0.071482878568.0 0.070647922969.0 0.069834080070.0 0.069040532171.0 0.068266503872.0 0.067511259473.0 0.066774100374.0 0.066054362875.0 0.065351416076.0 0.064664659377.0 0.063993521278.0 0.063337457279.0 0.062695948280.0 0.062068499081.0 0.061454637382.0 0.0608539117 83.0 0.060265891284.0 0.059690163685.0 0.059126334986.0 0.058574027887.0 0.058032881288.0 0.057502549189.0 0.056982699990.0 0.056473015891.0 0.055973191792.0 0.055482935193.0 0.055001964994.0 0.054530011295.0 0.054066814696.0 0.053612125897.0 0.053165704998.0 0.052727321299.0 0.0522967526100.0 0.0518737853101.0 0.0514582132102.0 0.0510498380103.0 0.0506484683104.0 0.0502539197105.0 0.0498660140106.0 0.0494845798107.0 0.0491094512108.0 0.0487404681109.0 0.0483774760110.0 0.0480203256111.0 0.0476688725112.0 0.0473229772113.0 0.0469825047114.0 0.0466473244115.0 0.0463173100116.0 0.0459923394117.0 0.0456722940118.0 0.0453570593119.0 0.0450465242120.0 0.0447405812121.0 0.0444391259122.0 0.0441420572123.0 0.0438492771124.0 0.0435606905125.0 0.0432762052126.0 0.0429957316127.0 0.0427191829128.0 0.0424464746129.0 0.0421775249130.0 0.0419122542131.0 0.0416505852132.0 0.0413924428133.0 0.0411377539134.0 0.0408864476135.0 0.0406384549136.0 0.0403937087137.0 0.0401521437138.0 0.0399136963139.0 0.0396783048140.0 0.0394459089141.0 0.0392164502142.0 0.0389898715143.0 0.0387661174144.0 0.0385451338145.0 0.0383268679146.0 0.0381112684147.0 0.0378982853148.0 0.0376878698149.0 0.0374799743150.0 0.0372745524151.0 0.0370715590152.0 0.0368709499153.0 0.0366726822154.0 0.0364767137155.0 0.0362830036156.0 0.0360915118157.0 0.0359021994158.0 0.0357150281159.0 0.0355299609160.0 0.0353469614161.0 0.0351659940162.0 0.0349870241163.0 0.0348100178164.0 0.0346349421165.0 0.0344617645166.0 0.0342904534167.0 0.0341209780168.0 0.0339533080169.0 0.0337874138170.0 0.0336232666171.0 0.0334608381 172.0 0.0333001006 173.0 0.0331410270 174.0 0.0329835910 175.0 0.0328277666 176.0 0.0326735285 177.0 0.0325208518 178.0 0.0323697123 179.0 0.0322200861 180.0 0.0320719500 181.0 0.0319252812 182.0 0.0317800574 183.0 0.0316362566 184.0 0.0314938575 185.0 0.0313528391 186.0 0.0312131807 187.0 0.0310748622 188.0 0.0309378640 189.0 0.0308021665 190.0 0.0306677509 191.0 0.0305345985 192.0 0.0304026910 193.0 0.0302720107 194.0 0.0301425399 195.0 0.0300142615 196.0 0.029******* 197.0 0.029******* 198.0 0.029******* 199.0 0.029******* 200.0 0.029******* 201.0 0.029******* 202.0 0.029******* 203.0 0.029******* 204.0 0.028******* 205.0 0.028******* 206.0 0.028******* 207.0 0.028******* 208.0 0.028******* 209.0 0.028******* 210.0 0.028******* 211.0 0.028******* 212.0 0.028******* 213.0 0.027******* 214.0 0.027******* 215.0 0.027*******216.0 0.027*******217.0 0.027*******218.0 0.027*******219.0 0.027*******220.0 0.027*******221.0 0.027*******222.0 0.0269466153223.0 0.0268458877224.0 0.0267459700225.0 0.0266468523226.0 0.0265485248227.0 0.0264509777228.0 0.0263542015229.0 0.0262581869230.0 0.0261629247231.0 0.0260684057232.0 0.025*******233.0 0.025*******234.0 0.025*******235.0 0.025*******236.0 0.025*******237.0 0.025*******238.0 0.025*******239.0 0.025*******240.0 0.025*******241.0 0.025*******242.0 0.025*******243.0 0.024*******244.0 0.024*******245.0 0.024*******246.0 0.024*******247.0 0.024*******248.0 0.024*******249.0 0.024*******250.0 0.024*******251.0 0.024*******252.0 0.024*******253.0 0.024*******254.0 0.024*******255.0 0.024*******256.0 0.023*******257.0 0.023*******258.0 0.023*******259.0 0.023*******260.0 0.023*******261.0 0.023*******262.0 0.023*******263.0 0.023*******264.0 0.023*******265.0 0.023*******266.0 0.023*******267.0 0.023*******268.0 0.023*******269.0 0.022*******270.0 0.022*******271.0 0.022*******272.0 0.022*******273.0 0.022*******274.0 0.022*******275.0 0.022*******276.0 0.022*******277.0 0.022*******278.0 0.022*******279.0 0.022*******280.0 0.022*******281.0 0.022*******282.0 0.022*******283.0 0.021*******284.0 0.021*******285.0 0.021*******286.0 0.021*******287.0 0.021*******288.0 0.021*******289.0 0.021*******290.0 0.021*******290.1 0.021*******290.2 0.021*******290.3 0.021*******290.4 0.021*******290.5 0.021*******290.6 0.021*******290.7 0.021*******290.8 0.021*******290.9 0.021*******291.0 0.021*******291.1 0.021*******291.2 0.021*******291.3 0.021******* 291.4 0.021******* 291.5 0.021******* 291.6 0.021******* 291.7 0.021******* 291.8 0.021******* 291.9 0.021******* 292.0 0.021******* 292.1 0.021******* 292.2 0.021******* 292.3 0.021******* 292.4 0.021******* 292.5 0.021******* 292.6 0.021******* 292.7 0.021******* 292.8 0.021******* 292.9 0.021******* 293.0 0.021******* 293.1 0.021******* 293.2 0.021******* 293.3 0.021******* 293.4 0.021******* 293.5 0.021******* 293.6 0.021******* 293.7 0.021******* 293.8 0.021******* 293.9 0.021******* 294.0 0.021******* 294.1 0.021******* 294.2 0.021******* 294.3 0.021******* 294.4 0.021******* 294.5 0.021******* 294.6 0.021******* 294.7 0.021******* 294.8 0.021******* 294.9 0.021******* 295.0 0.021******* 295.1 0.021******* 295.2 0.021******* 295.3 0.021******* 295.4 0.021******* 295.5 0.021******* 295.6 0.021******* 295.7 0.021******* 295.8 0.021******* 295.9 0.021******* 296.0 0.021******* 296.1 0.021******* 296.2 0.021******* 296.3 0.021******* 296.4 0.021******* 296.5 0.021******* 296.6 0.021******* 296.7 0.021******* 296.8 0.021******* 296.9 0.021******* 297.0 0.021******* 297.1 0.021******* 297.2 0.021******* 297.3 0.021******* 297.4 0.021******* 297.5 0.021******* 297.6 0.021******* 297.7 0.021******* 297.8 0.021******* 297.9 0.021******* 298.0 0.021******* 298.1 0.021******* 298.2 0.021******* 298.3 0.021******* 298.4 0.021******* 298.5 0.021******* 298.6 0.021******* 298.7 0.021******* 298.8 0.021******* 298.9 0.021******* 299.0 0.021******* 299.1 0.020******* 299.2 0.020******* 299.3 0.020******* 299.4 0.020******* 299.5 0.020******* 299.6 0.020******* 299.7 0.020******* 299.8 0.020******* 299.9 0.020******* 300.0 0.020*******。