# hw8_LeiP_p2.m - % % % % % Pok Cheng Lei MAE M20...

• Homework Help
• 2
• 100% (5) 5 out of 5 people found this document helpful

This preview shows page 1 - 2 out of 2 pages.

% Pok Cheng Lei% MAE M20% UID:404615069% Newton's method% This script usees Newton's method to find the roots of sine function.clear; close all; clc;%% First attempt% Initialize functionsf = @sin;fp = @cos;% Initial guess of xx0 = 1;delta = 10^-10;fEvalMax = 20;% Call Newton's method function to obtain roots[xc, fEvals] = Newton(f, fp, x0, delta, fEvalMax);fprintf('When x0 = %f, the root is %f, and it evalutes %d times.\n', x0, xc, fEvals);%% Second attempt% Initialize functionsf = @sin;fp = @cos;% Initial guess of xx0 = 3;delta = 10^-10;fEvalMax = 20;% Call Newton's method function to obtain roots[xc, fEvals] = Newton(f, fp, x0, delta, fEvalMax);fprintf('When x0 = %f, the root is %f, and it evalutes %d times.\n', x0, xc, fEvals);%% Third attempt% Initialize functionsf = @sin;fp = @cos;% Initial guess of xx0 = 6;delta = 10^-10;fEvalMax = 20;% Call Newton's method function to obtain roots[xc, fEvals] = Newton(f, fp, x0, delta, fEvalMax);fprintf('When x0 = %f, the root is %f, and it evalutes %d times.\n', x0, xc,
End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Winter
Professor
Eldredge
Tags
Inverse function, initial guess, Jamsh d al K sh
• • • 