欢迎来到天天文库
浏览记录
ID:50557143
大小:19.33 KB
页数:1页
时间:2020-03-10
《二分法和割线法求非线性方程的解.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、主程序为:%计算方法上机第八题clc;clear;symsxaff=cos(x*sin(a));%定义积分函数t1=0;t2=pi;l1=2;l2=3;e1=10^-5;e2=10^-4;e3=10^-3;f1=subs(f,x,l1);f2=subs(f,x,l2);s1=romberg(t1,t2,f1,e1);%调用Romberg积分函数s2=romberg(t1,t2,f2,e1);ifs1*s2>0disp('Thereisnorootintherangeof[2,3].');elsewhile(l2-l1)>e3%二分法
2、确定包含解的小区间l3=(l1+l2)/2;f3=subs(f,x,l3);s3=romberg(t1,t2,f3,e1);ifs1*s3<0l2=l3;s2=s3;elsel1=l3;s1=s3;endenddisp(['Therootisintherangeof[',num2str(l1),',',num2str(l2),'].']);while(l2-l1)>e2%割线法确定具体的解l3=l2;l2=l2-(l2-l1)*s2/(s2-s1);f2=subs(f,x,l2);s2=romberg(t1,t2,f2,e1);l1
3、=l3;s1=s2;enddisp(['Theapproximatesolutionis:',num2str(l2)]);%输出解end
此文档下载收益归作者所有