Question

In: Advanced Math

How can I code this problem in MATLAB: a) Find the approximations to within 10-4 to...

How can I code this problem in MATLAB:

a) Find the approximations to within 10-4 to all real zeros of the following polynomials using Newton's method.?

f(x)=x3 - 2*x2- 5.

b) Find approximations to within 10-5 to all the zeros of each of the following polynomials by first
finding the real zeros using Newton’s method and then reducing to polynomials of lower degree to
determine any complex zeros.

f(x)=x4 + 5x3 - 9*x2 - 85*x - 136.

Solutions

Expert Solution


%Matlab code for finding roots using Newton methods
clear all
close all

%function for which root have to find
fun=@(x) x.^3 - 2.*x.^2- 5;
fprintf('For the function f(x)=\n')
disp(fun)
xx=linspace(-2,4);
%initial guess
x0=10;
%error limit
n=10^-4;
[root]=newton_method(fun,x0,n);
fprintf('\tRoot of the function using Newton method is %f.\n',root)


%function for which root have to find
fun=@(x) x.^4 + 5.*x.^3- 9.*x.^2 -85.*x -136;
fprintf('\nFor the function f(x)=\n')
disp(fun)
xx=linspace(-2,4);
%initial guess
x0=10;
%error limit
n=10^-4;
[root1]=newton_method(fun,x0,n);
fprintf('\t1st Root of the function using Newton method is %f.\n',root1)

%initial guess
x0=-10;
%error limit
n=10^-4;
[root2]=newton_method(fun,x0,n);
fprintf('\t2nd Root of the function using Newton method is %f.\n',root2)

fprintf('\tNow complex root occured for the equation is ')
syms x
p = x.^4 + 5.*x.^3- 9.*x.^2 -85.*x -136;
p2 = (x-root1)*(x-root2);

[q, r] = quorem(p, p2);
disp(vpa(q,2))

fprintf('So that the complex roots are \n')
fprintf('\t-2.5 +1.32287565553229i \n\t-2.5 -1.32287565553229i\n\n')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Matlab function for Newton Method
function [root]=newton_method(fun,x0,n)
syms x
g1(x) =diff(fun,x);   %1st Derivative of this function
xx=x0;            %initial guess]
%Loop for all intial guesses
    maxit=10000;
    for i=1:maxit
        x2=double(xx-(fun(xx)./g1(xx))); %Newton Raphson Formula
        cc=abs(fun(x2));                 %Error
        err(i)=cc;
        xx=x2;
        if cc<=n
            break
        end
      
    end
    root=xx;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Related Solutions

Write a program using Newton's method: Use your programs to find approximations to within 10^(-4) to...
Write a program using Newton's method: Use your programs to find approximations to within 10^(-4) to all zeros of the following cubic polynomials. Use |P_(n+1)-P_n| as a measure of the error in the iteration. Save all of the iterations. What are your conclusions? (a) f(x) = x^3-5x^2 + 2x (b) f(x) = x^3-2x^2-5 The program has to be used with MATLAB. I'm still learning how to use the program. I would love some help and tips on solving these methods....
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem...
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandstop filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce the below is the Problem 1 initail code .. you can use it Matlab The following cilab code generates a 10-second “chirp”...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
pls, I need Matlab code for, OFDM modulation (Matlab demo by at least 4 carriers)
pls, I need Matlab code for, OFDM modulation (Matlab demo by at least 4 carriers)
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has...
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has shows that In implementing SOR method in MATLAB, one should not calculate Tw and cw by formulas Tw = (D -wL)^(-1)[(1-w)D+wU)] and Cw = w(D-wL)^(-1)b , where w stands for omega and using MATLAB's built-in inv function, since this function requires O(n^3) flops and therefore the whole matter loses its point. I have tried for many times but I can't get the correct answers....
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Find the approximations Ln, Rn, Tn, and Mn for n = 5, 10, and 20. Then...
Find the approximations Ln, Rn, Tn, and Mn for n = 5, 10, and 20. Then compute the corresponding errors EL, ER, ET, and EM. (Round your answers to six decimal places. You may wish to use the sum command on a computer algebra system.) 1 22xexdx 0   n     Ln Rn Tn Mn 5 10 20     n     EL ER ET EM 5 10 20
how can i get the code for this problem in visual basic? Create a Windows Forms...
how can i get the code for this problem in visual basic? Create a Windows Forms applications called ISP (Internet Service Provider) Project. You must enter the number of hours for the month and select your desire ISP package. An ISP has three different subscription packages for it's customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2 per hours. Package B: For $13.95 per month 20 hours of access are provided. Additional...
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
Practice for Matlab. You can create own f(x). a. Write code to find and plot a...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a root using the modified secant method b. Find the roots using the roots command - identify and plot root of interest c. Use polyder and roots to find and plot the minimum value d. use fminbnd to find and plot minimum value Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT