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

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”...
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
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!
Could you create me a secant code in Matlab program? That's I can keep it and...
Could you create me a secant code in Matlab program? That's I can keep it and use it for any time?
how can i find proposition of postpartum depression theory ? how can i find proposition of...
how can i find proposition of postpartum depression theory ? how can i find proposition of any nursing theory ?
There is no perfect example for perfectly competitive markets. However, we can find a few approximations....
There is no perfect example for perfectly competitive markets. However, we can find a few approximations. Please first review the main characteristics of perfectly competitive markets. Then give an example for a perfectly competitive firm. Explain how this firm meets each characteristic in these markets.
I want the code for the 2D Ising model using Matlab
I want the code for the 2D Ising model using Matlab
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT