




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、加步探索法#include#includeusing namespace std;double fun(double t)return (t*t*t-2*t+1);double max(double a,double b)if(ab)return a;else return b;double min(double a,double b)if(ab)return b;else return a;double Addstep(double(*pfun)(double t)int k=0;double t0=0,h=1,r=2,t,a=0,b=0;t=t0+h;doif(fun(t)fun(t0)h
2、=r*h;t0=t;t=t0+h;k+;elseif(k=0)h=-h;k+; elsea=min(t0,t);b=max(t0,t);return a;return b;while(a=b);cout 探索区间为:min(t0,t),max(t0,t)endl;int main()Addstep(fun);return 0;对分法#include#includeusing namespace std;double fun(double t)return (t*t-3*t);double dfun(double t)return (2*t-3);void Dichotomous(double(
3、*pfun)(double t),double (*pdfun)(double t)int maxflag=1000,k=1;double a=-3,b=5,c,err=0.1,t;doc=(a+b)/2;if(dfun(c)0)b=c;elsea=c;b=c;k+;while(fabs(a-b)err&k=maxflag)coutendl对分法迭代失败!迭代次数为k=kendl;elsecoutendl 对分法迭代成功!迭代次数为k=k-1endl;cout迭代结果:近似根为root=tendl;cout 函数值近似为:f(root)=fun(t)endl;int main()Dichoto
4、mous(fun,dfun);return 0;Newton切线法#include#includeusing namespace std;double fun(double t)return (t*t*t-2*t+1);double dfun(double t)return (3*t*t-2);void NewtonIterative(double(*pfun)(double t),double (*pdfun)(double t)int maxflag=1000,k=1;double t0=1,err=0.01,t;dot0=t;t=t0-pfun(t0)/pdfun(t0);k+;whil
5、e(fabs(t-t0)err&k=maxflag)coutendl 牛顿迭代失败!迭代次数为k=kendl;elsecoutendl 牛顿迭代成功!迭代次数为k=k-1endl;cout 迭代结果:近似根为root=tendl;cout 函数值近似为:f(root)=fun(t)endl;int main()NewtonIterative(fun,dfun);return 0;黄金分割法#include#includeusing namespace std;double fun(double t)return (t*t+2*t);void Goldensection(double(*pfun
6、)(double t)int maxflag=1000,k=1;double a=-3,b=5,err=0.001,t,t1,t2;dot1=a+0.618*(b-a);t2=b-0.618*(b-a);if(t1=t2)a=t2;b=t1;else if(t1err&k=maxflag)coutendl黄金分割法迭代失败!迭代次数为k=kendl;elset=(a+b)/2;coutendl 黄金分割法迭代成功!迭代次数为k=k-1endl;cout 迭代结果:近似根为root=tendl;cout 函数值近似为:f(root)=fun(t)endl;int main()Goldensect
7、ion(fun);return 0;抛物线插值法#include#includeusing namespace std;double fun(double x)return (8*x*x*x-2*x*x-7*x+3);double max(double a,double b)if(ab)return a;else return b;double min(double a,double b)if(ab)return b;else return a;void Parainterpolation(double(*pfun)(double x)double a=0,b=2,err=0.001,x=0,x0=1,f,f0;dox=(x0*x0-b*b)*fun(a)+(b*b-a*a)*fun(x0)+(a*a-x0*x0)*fun(b)/(2*(x0-b)*fun(a)+(b-a)*fun(x0)+(a-x0)*fun(b);f0=fun(x0);f=fun(x);if(f=f0)a=min(x,x0);b=max(x,x0);x0=(a+b)/2;else if(fun(x)-f0)*(x-x0)0)b=max(x,x0);x0=min(x,x0); elsea=min(x,x0);x0=max(x,x0);while(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025钢筋加工承包合同
- 2025智能设备销售的代理合同
- 2025二级建筑师房建聘用合同
- 2025新型环保材料研发与技术转让合同
- 2025停车位使用权转让合同范本
- 登山活动赞助合同协议
- 电缆架机租赁合同协议
- 生产设备拆除合同协议
- 环保劳务报酬合同协议
- 疆校服采购合同协议
- 公务员体检须知
- 2025-2030清洁能行业市场发展分析与发展趋势及投资前景预测报告
- 浙江国企招聘2025嘉兴国际商务区投资建设集团有限公司招聘13人笔试参考题库附带答案详解
- 烟花购销合同协议
- 137案例黑色三分钟生死一瞬间事故案例文字版
- SWITCH塞尔达传说旷野之息-1.6金手指127项修改使用说明教程
- 数据结构课程设计马的遍历
- 小学生美术课件-第3课-设计手抄报--冀美版(共24张PPT)ppt课件
- 藏外佛教文献W06n0055 大黑天神道场仪
- 煤矿应急预案之-地震应急救援预案演练报告23-1
- 监控安装施工流程图
评论
0/150
提交评论