📄 nlineq_driver.m
字号:
%% nlineq_driver.m% % use bisect.m and newt1d.m to compute an approximation% of the root of f(x) = cos(x)*cosh(x)+1%% Matthias Heinkenschloss% Department of Computational and Applied Mathematics% Rice University%disp(' ')disp(' Find the root of f(x) = cox(x)*cosh(x)+1 ')disp(' ')disp(' Hit return to continue with the Bisection Method')disp(' ')pausef = 'coscosh';a = 1.6;b = 2;tolx = 1.e-7;[a, b, x, ithist, iflag] = bisect( f, a, b, tolx );fprintf('\n The Bisection Method returned with iflag = %d \n ', iflag)fprintf('\n Bisection Method \n ')fprintf(' iter a b c f(c) \n ')for i = 1:size(ithist,1) fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))enddisp(' ')disp(' Hit return to continue with Regula Falsi')disp(' ')pausea = 1.6;b = 2;tolf = 1.e-14;[a, b, x, ithist, iflag] = regulafalsi( f, a, b, tolf );fprintf('\n Regula falsi returned with iflag = %d \n ', iflag)fprintf('\n Regula Falsi \n ')fprintf(' iter a b c f(c) \n ')for i = 1:size(ithist,1) fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))enddisp(' ')disp(' Hit return to continue with Newton''s Method')disp(' ')pausex = 2;[x, ithist, iflag] = newt1d( f, x, 1.e-15, 1.e-15, 20 );fprintf('\n Newton''s Method returned with iflag = %d \n ', iflag)fprintf('\n Newton''s Method \n ')fprintf(' iter x f(x) -f(x)/f''(x) \n ')for i = 1:size(ithist,1) fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))enddisp(' ')disp(' Hit return to continue with Secant Method')disp(' ')pausex = 2; x1 = 2.01[x, ithist, iflag] = secant( f, x, x1, 1.e-15, 1.e-15, 20 )fprintf('\n Secant Method returned with iflag = %d \n ', iflag)fprintf('\n Secant Method \n ')fprintf(' iter x f(x) -f(x)/f''(x) \n ')for i = 1:size(ithist,1) fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))enddisp(' ')disp(' Hit return to continue with Newton''s Method')disp(' ')pausef = 'xsinx2';x = 0.5;[x, ithist, iflag] = newt1d( f, x, 1.e-12, 1.e-15, 20 );fprintf('\n Newton''s Method returned with iflag = %d \n ', iflag)fprintf('\n Newton''s Method \n ')fprintf(' iter x f(x) -f(x)/f''(x) \n ')for i = 1:size(ithist,1) fprintf('%4d &$ %13.8e $&$ %13.8e $&$ %13.8e $\\\\ \n ', ithist(i,:))end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -