二分法matlab实现

更新时间:2023-06-23 06:41:17 阅读: 评论:0

⼆分法matlab实现
function bic(file_name, a, c, xmin, xmax, n_points)
% file_name 是要计算的函数
% a, c, b 是含根区间上下限和中间值
手动档汽车起步>dramatic irony% xmin,xmax 是图形横坐标的最⼩和最⼤值
保持联系英文% n_points 是⾃变量X的采样数
% Y_a, Y_c 是当前端点的y值
% it 是迭代的次数
clf, hold off
clear Y_a, clear Y_c
wid_x = xmax - xmin;
dx = (xmax - xmin) / n_points;
xp = xmin: dx: xmax;
yp = feval(file_name, xp);
plot(xp, yp, 'r'); % y=f(x)
xlabel('x'); ylabel('f(x)'); title('Biction Method');
hold on
ymin = min(yp);
ymax = max(yp);
wid_y = ymax - ymin;
yp = 0.0 * xp;
plot(xp, yp); % x坐标轴
fprintf('Biction Scheme \n\n');
fprintf('it  a  b  c  fa = f(a)');
fprintf('  fc = f(c)  abs(fc - fa)  abs(c - a)/2\n');
tolerance = 0.000001; % 绝对误差限
it_limit = 30; % 迭代的最⾼次数
it = 0;
Y_a = feval(file_name, a);
Y_c = feval(file_name, c);
plot([a, a], [Y_a, 0], 'black');
text(a, -0.1 * wid_y, 'x=a');
plot([c, c], [Y_c, 0], 'black');
text(c, -0.3 * wid_y, 'x=c');
if(Y_a * Y_c > 0)
fprintf('f(a)f(c)>0 \n');
el
while 1
it = it + 1;
b = (a + c) / 2;
Y_b = feval(file_name, b);
plot([b, b], [Y_b, 0], ":")
美国大学排名2013
plot(b, 0, 'o')
tme>选择阅读答案
if it<4
text(b, wid_y/20, [num2str(it)])
end
fprintf('%3.0f %10.6f %10.6f', it, a, b);
fprintf('%10.6f %10.6f %10.6f', c, Y_a, Y_c);
fprintf(' %12.3e %12.3e\m', abs(Y_c-Y_a), abs(c-a)/2);
if(abs(c-a)/2 <= tolerance)
fprintf('Tolerance is satisfied. \n');
break
end
if(it>it_limit)
fprintf('Iteration limit exceeded. \n');
minutes怎么读break
end
if(Y_a * Y_b <= 0)
c = b;
c = b;
Y_c = Y_b;
el
a = b;
laptop是什么意思
Y_a = Y_b;
end
endremedy是什么意思
fprintf('Final result ; Root = %12.6f \n', b)
end
x = b;
plot([x,x], [0.05 * wid_y, 0.2 * wid_y], 'g');
天堂的午餐
text(x, 0.25 * wid_y, 'Final solution');
plot([x, (x-wid_x * 0.004)], [0.05 * wid_y, 0.09 * wid_y], 'r'); plot([x, (x+wid_x * 0.004)], [0.05 * wid_y, 0.09 * wid_y], 'r');
function y=ex_5x2(x)
y=exp(x) - 5.* x .^2

本文发布于:2023-06-23 06:41:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1019180.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:阅读   实现   计算   区间
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图