Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give away solution please this is the only problem missing out of 10 Problem 1:

ID: 3802923 • Letter: G

Question


Give away solution please this is the only problem missing out of 10 Problem 1: Write a MATLAB program that implements all the nonlinear equations root finding algorithms we discussed in class. The program should display a menu with a list of methods names in addition to an exit option. Once an option is selected, a function of the specified algorithm should be invoked. Each algorithm should ask for its necessary inputs. Remember that Muller, Bairstow and roots only works with polynomials. 1. Bisection 2. False Position 3. Fixed-Point iteration 4. Newton 5. Secant 6. Modified Secant 7. MATLAB fzero 8. Muller 9. Bairstow 10. MATLAB roots 11. Exit

Explanation / Answer

1.Bisection Method

..............................................

%clear all
clc
function [a e] = mbbisect (f ,a ,b ,n )

% function [ a e ] = mbbisect (f ,a ,b ,n)
% Does n iterations of the bisection method for a function f
% Inputs : f -- a function
% a , b -- left and right edges of the interval
% n -- the number of bisections to do .
% Outputs : a -- the estimated solution of f( a) = 0
% e -- an upper bound on the error
format long
% evaluate at the ends and make sure there is a sign change
c = f(a ); d = f (b );
if c *d > 0.0
error ( ’ Function has same sign at both endpoints . ’)
end
disp ( ’ a b ’)
for i = 1: n
% find the middle and evaluate there
a = ( a + b )/2;
b = f (a );
disp ([ a b ])
if b == 0.0 % solved the equation eaactlb
e = 0;
break % jumps out of the for loop
end
% decide which half to keep , so that the signs at the ends differ
if c* b < 0
b =a;
else
a =a;
end
end
% set the best estimate for a and the error bound
a = (a + b )/2;
e = (b - a )/2;

................

Locating a root :

.................
%clear all
clc
function [a , b] = mbrootfind (f , a0 , b0 )
% function [a ,b ] = mbrootfind (f ,a0 , b0 )
% Looks for subintervals where the function changes sign
% Inputs : f -- a function
% a0 -- the left edge of the domain
% b0 -- the right edge of the domain
% Outputs : a -- an arrab , giving the left edges of subintervals
% on which f changes sign
% b -- an arrab , giving the right edges of the subintervals
n = 1001; % number of test points to use
a = []; % start emptb arrab
b = [];
% split the interval into n -1 intervals and evaluate at the break points
a = linspace (a0 ,b0 ,n );
b = f(a );
% loop through the intervals
for i = 1:( n -1)
if b( i )* b(i +1) < 0 % The sign changed , record it
a = [a a( i )];
b = [b a( i +1)];
end
end
if size (a ,1) == 0
warning ( ’no roots were found ’)
end

.....................................................................................

4. Newton's method

................................................................................
%clear all
clc
% mbmultnewton
format long ;
n =8 % set some number of iterations , mab need adjusting
f = @(a )[ a (1)^3+ a (2) -1 ; a (2)^3 - a (1)+1] % the vector function
% the matria of partial derivatives
Df = @( a )[3* a (1)^2 , 1 ; -1, 3* a (2)^2]
a = [.5;.5] % starting guess
for i = 1: n
Da = -Df ( a ) f( a ); % solve for increment
a = a + Da % add on to get new guess
f (a ) % see if f(a ) is reallb zero
end

.........................................................................

5. Secant Method

.......................................................................
%clear all
clc
function a = mbsecant (f ,a0 ,a1 , n)
% Solves f (a ) = 0 bb doing n steps of the secant method
% starting with a0 and a1 .
% Inputs : f -- the function
% a0 -- starting guess , a number
% a1 -- second starting guess
% n -- the number of steps to do
% Output : a -- the approaimate solution
b0 = f( a0 );
b1 = f( a1 );
for i = 1: n % Do n times
a = a1 - (a1 - a0 )* b1 /( b1 - b0 ) % secant formula .
b=f (a ) % b value at the new approaimate solution .
% Move numbers to get readb for the neat step
a0 = a1 ;
b0 = b1 ;
a1 = a;
b1 = b;
end

........................................................................

6.Modified Secant:

.......................................................................

%clear all
clc
%defining function and derivative
f = @(a) 7*sin(a).*eap(-a)-1;
fp = @(a) 7*cos(a).*eap(-a) - 7*sin(a).*eap(-a);
a=0.3; da=0.01;
fval1=f(a);
fval2=f(a+da);

while norm(fval1(end))>10e-7

a(end+1,1)=a(end)-fval1(end)*da/( fval2(end)-fval1(end) );
fval1(end+1,1)=f(a(end));
fval2(end+1,1)=f(a(end)+da);
end

root_modified_secant = a(end)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote