I need the source code in MATLAB Thank you Cancellation Prec

I need the source code in MATLAB. Thank you..

Cancellation, Precision and Loss of Precision. Consider finding the roots of the quadratic polynomial, f(x) = ax^2 + bx + c. Suppose we are trying to solve this equation for a = 0.5, b = 1000, c=5 times 10^-7. The quadratic formula says that one of the roots is, x = -b + squareroot b^2 - 4ac/2a Use the Loss of Precision Theorem (with base 10) to establish the number of accurate digits in the root. Recall that double precision numbers give about 15 or 16 decimal digits of precision. Compute the \"true\" root using the Matlab roots function. Compute the root in Matlab using the formula in Equation (1). How accurate is your result? Does it agree with your answer in part (a)? Modify the above formulation of the quadratic formula to remove this problem. Verify your results by computing the root with the new formulation in Matlab.

Solution

% This m-file will solve the quadratic equation :ax^2 + bx + c = 0 function Quad= Quadratic(A,B,C)

% A=1;

% B=2;

% C=3;

%If-Else statement for if A=0

if A==0,

    X= -C/B;

else

    X(1) = (-B+sqrt(B^2-4*A*C))/(2*A);

    X(2) = (-B-sqrt(B^2-4*A*C))/(2*A);

     disp(X(1))

     disp(X(2))

     fprintf(\'X(1) = %f \ \',X(1));

    fprintf(\'X(2) = %f \ \',X(2));

end

now computing the true root

function [a , b] = myrootfind (f , a0 , b0 )

% function [a ,b ] = myrootfind (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 array , giving the left edges of subintervals

% on which f changes sign

% b -- an array , giving the right edges of the subintervals

n = 1001; % number of test points to use

a = []; % start empty array

b = [];

% split the interval into n -1 intervals and evaluate at the break points

x = linspace (a0 ,b0 ,n );

y = f(x );

% loop through the intervals

for i = 1:( n -1)

if y( i )* y(i +1) < 0 % The sign changed , record it

a = [a x( i )];

b = [b x( i +1)];

end

end

if size (a ,1) == 0

warning ( ’no roots were found ’)

end

I need the source code in MATLAB. Thank you.. Cancellation, Precision and Loss of Precision. Consider finding the roots of the quadratic polynomial, f(x) = ax^2
I need the source code in MATLAB. Thank you.. Cancellation, Precision and Loss of Precision. Consider finding the roots of the quadratic polynomial, f(x) = ax^2

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site