第一范文网 - 专业文章范例文档资料分享平台

信息与计算科学专业实习报告

来源:用户分享 时间:2025/5/17 5:32:46 本文由沐浅 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

信息与计算科学专业 专业实习报告

附录

function [x,fx,xflag]=find_roots1(f,c1,c2,rel_err) % f is the name of the function to be solved

% c1,c2 are the min and max bounds of x respectively % rel_err is the relative error,that is abs(f1n-f2n)/abs(f1-f2) % where f1n, f2n are the function values at the c1n and c2n % f1n, f2n are the function values at c1 and c2 % xflag is -1 if there's no root in range (c1,c2) % xflag equals to 1 if there is a root in range (c1,c2) % x is the root solved % fx is its value % example

% [x,fx,xflag]=find_roots1(@sin,0.1,pi+0.1,1e-6) %{ c1=0.01; c2=pi+0.1; rel_err=1e-3; f=@sin; %} xflag=-1; f1=feval_r(f,c1); f2=feval_r(f,c2); abs_f1_2=abs(f1-f2); if abs(f1) <= rel_err*abs_f1_2 x=c1; fx=f1; xflag=1; return;

elseif abs(f2) <= rel_err*abs_f1_2 x=c2; fx=f2; xflag=1; return;

21

信息与计算科学专业 专业实习报告

elseif f1*f2 >0 x=nan; fx=nan; return; else for i1=1:100 c0=(c1+c2)/2; f0=feval_r(f,c0);

if abs(f0) <= rel_err*abs_f1_2 x=c0; fx=f0; xflag=1; return; elseif f1*f0 >0 c1=c0; f1=f0; else c2=c0; f2=f0; end

if abs(f1-f2)

elseif abs(f1-f2)>100*abs_f1_2 xflag=-1; x=nan; fx=nan; return; end end end

22

搜索更多关于: 信息与计算科学专业实习报告 的文档
信息与计算科学专业实习报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4183i0s5jw3ibqw7sipv_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top