欢迎来到天天文库
浏览记录
ID:47020549
大小:112.50 KB
页数:8页
时间:2019-06-16
《数值分析实验2》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、《数值分析》课程实验报告学院:数学学院专业:信息与计算科学班级:10信计学号:姓名8《数值分析》课程实验报告学院:数学学院专业:信息与计算科学班级:10信计学号:姓名8实验名称用牛顿迭代法求解非线性方程成绩8一、实验目的1.了解求解非线性方程的解的常见方法。2.编写牛顿迭代法程序求解非线性方程。二、实验内容分别用初值,和求,要求精度为。三、算法描述牛顿法实质是一种线性化方法,其基本思想是将非线性方程逐步归结为某种线性方程来求解。对于牛顿法来说它的一般步骤为:1)选定初始近似值x0,计算f0=f(x0),f0'=f'(x0)2)按公式想x(k+1=)=x(k)-f(xk)/f'(xk)进行
2、迭代下去3)使得所求的根在精度的范围内4)如果迭代次数达到预先指定的次数或f1'=0,则方法不可以进行下去,否则依次进行迭代下去,直到结果出现为止。四、实验步骤1.根据实验题目,给出题目的matlab程序。2.上机输入和调试自己所编的程序。3.实验结果分析。五、程序1)牛顿切线法:function[k,xk,yk,piancha,xdpiancha]=newtonqx(x0,tol,ftol,gxmax)x(1)=x0;fori=1:gxmaxx(i+1)=x(i)-fnq(x(i))/(dfnq(x(i))+eps);piancha=abs(x(i+1)-x(i));xdpiancha
3、=piancha/(abs(x(i+1))+eps);i=i+1;xk=x(i);yk=fnq(x(i));[(i-1)xkykpianchaxdpiancha]if(abs(yk)4、(xdpianchagxmaxdisp('Çë×¢Ò⣺µü´ú´ÎÊý³¬¹ý¸ø¶¨µÄ×î´óÖµgxmax¡£')k=i-1;xk=x(i);[(i-1)xkykpianchaxdpiancha]return;end[(i-1),5、xk,yk,piancha,xdpiancha]';M文件:1.functiony=fnq(x)y=x^2-113;82.functiony=dfnq(x)y=2*x;运行结果:1.初值为0.01:kxkYkpianchaxdpiancha10.00063.190.0006020.00287.980.0028030.001420.0014040.00714.990.0071050.00351.250.0035060.01773.110.01760.000170.08877.760.08810.00180.0451.910.04370.001923.75145121.23950.894316、014.25490.29.49670.66621111.091103.16350.28521210.640.20.45120.04241310.6300.00960.00091410.630002.初值为10时kxkykpianchaxdpiancha110.650.420.650.061210.6300.01980.0019310.6300041063010003.初值为300时:kxkykpianchaxdpiancha10.0152.24440.0150.000120.07555.58280.07470.00130.03851.3680.0370.001420.7101315.907、6517.77380.8582513.083258.16947.62690.583610.86014.9422.22310.2047710.63260.05180.22750.0214810.630100.00240.0002910.63010002)开方方法:function[k,xk,yk,piancha,xdpiancha,P]=kainfang(x0,c,n,tol,gxmax)x(1)=x0;fori=1:gxmax8u(i)=(x(i)^n-c)/(n*x(i)^(n-1));x(i+1)=x(i)-u(i);piancha=abs(x(i+1)-x(i));xdpianch8、a=piancha/(abs(x(i+1))+eps);i=i+1;xk=x(i);yk=fnq(x(i));[(i-1),xk,yk,piancha,xdpiancha]if(piancha9、(xdpianchagxmaxdisp('Çë×¢Ò⣺µü´ú´ÎÊý³¬¹ý¸ø¶¨µÄ×î´óÖµgxmax.')k=i-1;
4、(xdpianchagxmaxdisp('Çë×¢Ò⣺µü´ú´ÎÊý³¬¹ý¸ø¶¨µÄ×î´óÖµgxmax¡£')k=i-1;xk=x(i);[(i-1)xkykpianchaxdpiancha]return;end[(i-1),
5、xk,yk,piancha,xdpiancha]';M文件:1.functiony=fnq(x)y=x^2-113;82.functiony=dfnq(x)y=2*x;运行结果:1.初值为0.01:kxkYkpianchaxdpiancha10.00063.190.0006020.00287.980.0028030.001420.0014040.00714.990.0071050.00351.250.0035060.01773.110.01760.000170.08877.760.08810.00180.0451.910.04370.001923.75145121.23950.89431
6、014.25490.29.49670.66621111.091103.16350.28521210.640.20.45120.04241310.6300.00960.00091410.630002.初值为10时kxkykpianchaxdpiancha110.650.420.650.061210.6300.01980.0019310.6300041063010003.初值为300时:kxkykpianchaxdpiancha10.0152.24440.0150.000120.07555.58280.07470.00130.03851.3680.0370.001420.7101315.90
7、6517.77380.8582513.083258.16947.62690.583610.86014.9422.22310.2047710.63260.05180.22750.0214810.630100.00240.0002910.63010002)开方方法:function[k,xk,yk,piancha,xdpiancha,P]=kainfang(x0,c,n,tol,gxmax)x(1)=x0;fori=1:gxmax8u(i)=(x(i)^n-c)/(n*x(i)^(n-1));x(i+1)=x(i)-u(i);piancha=abs(x(i+1)-x(i));xdpianch
8、a=piancha/(abs(x(i+1))+eps);i=i+1;xk=x(i);yk=fnq(x(i));[(i-1),xk,yk,piancha,xdpiancha]if(piancha9、(xdpianchagxmaxdisp('Çë×¢Ò⣺µü´ú´ÎÊý³¬¹ý¸ø¶¨µÄ×î´óÖµgxmax.')k=i-1;
9、(xdpianchagxmaxdisp('Çë×¢Ò⣺µü´ú´ÎÊý³¬¹ý¸ø¶¨µÄ×î´óÖµgxmax.')k=i-1;
此文档下载收益归作者所有