Use muller Method to determine the real and complex roots of f(x) = x^3 - x2 + 3
ID: 1862984 • Letter: U
Question
Use muller Method to determine the real and complex roots of
f(x) = x^3 - x2 + 3 x - 2
f(x) = x^4 - 2 x^3 + 5 x^2 - x - 10
and, write a MATLAB script (with comments explaining each and every major step) to implement Muller's
method.
Explanation / Answer
Procedure to run the code: % Press F5 or RUN, then in command window a message would be displayed- % "Polynomial function of Order "n" is of type:a[1]X^n+a[2]X^(n-1)+ ..+a[n]X^1+a[n+1] % Type Coeff as "[ 1 2 3 ...]" i.e Row vector form." % Enter the values according to above order. % If polynomial is more than 1st order, it would ask for three initial guess for % iteration. % Please provide with three distinct numbers or else error message would be displayed. % e.g. % Enter the coefficient in order? [1 2 3 4 5] % Give the three initial guess point [x0, x1, x2]: [-1 0 1] % or any other three distinct number, % If the range of solution is known then using a value close to that range % might yeild a faster result. Or if you dont have any clue about value of root % then just press enter when ask for guess, and it would use default value % of [1 2 3]. function Muller() clc, clear all % Clears the command window and variables syms x % variable x declared symbol R_Accuracy = 1e-8; % No of digit for termination A_x = 0; % Function initiallization flag =1; % Flag will be used for terminating process Root_index =0; disp('Polynomial function of Order "n" is of type:a[1]X^n+a[2]X^(n-1)+ ..+a[n]X^1+a[n+1]'); disp('Type Coeff as "[ 1 2 3 ...]" i.e Row vector form'); Coeff = input('Enter the coefficient in order? '); [row_initial,col_initial] = size(Coeff); for i = 1:col_initial A_x = A_x + Coeff(i)*(x^(col_initial-i)); % Polynomial function building end clc disp('Polynomial is : '); disp(A_x) while(flag) [row,col] = size(Coeff); if (col ==1) flag =0; elseif(col==2) flag =0; Root_index = Root_index + 1; Root(Root_index)= -Coeff(2)/Coeff(1); disp(['Root found:' num2str(-Coeff(2)/Coeff(1)) '']); disp(' ') elseif(col >= 3) Guess = input('Give the three initial guess point [x0, x1, x2]: '); if isempty(Guess) Guess = [1 2 3]; disp('Using default value [1 2 3]') elseif(Guess == zeros(1,3)) break end disp(['Three initial guess are: ' num2str(Guess) ' ']); for i = 1:100 h1 = Guess(2)-Guess(1); h2 = Guess(3)-Guess(2); d1 = (polyval(Coeff,Guess(2))-polyval(Coeff,Guess(1)))/h1; d2 = (polyval(Coeff,Guess(3))-polyval(Coeff,Guess(2)))/h2; d = (d2-d1)/(h1+h2); b = d2 + h2*d; Delta = sqrt(b^2-4*polyval(Coeff,Guess(3))*d); if (abs(b-Delta)Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.