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

2) Write a seript m-file that calls the function nest to evaluate P-2), where P(

ID: 2247489 • Letter: 2

Question

2) Write a seript m-file that calls the function nest to evaluate P-2), where P(x)is defined in Problem 1 of the Theoretical Problems. You do not have to pass the 4h argument to the function (the base points)-just the first 3 arguments. Run your script and give the output. The function nestO is provided in the MATLAB Code folder in your eLeaming course Math 4334.701- FL17 or CS 4334.701 FL17. Note that using nestO may require a different number of flops from your result in Problem 1, but use as few flops as possible when applying nestO.

Explanation / Answer

a)

function [x1,x2]=quadroots(a,b,c)

%File: quadroots.m

%Purpose:
%This program finds the roots of the quadratic equation. It determines
%wether the roots are real or imaginery. It outputs regardless of the type
%of roots that the equation posses.
%
%Variables:
%a - Coefficient of x^2 term.
%b - Coefficient of x term.
%c - Constant term
%Discriminant - Discriminant of equation.
%x1 - First Solution.
%x2 - Second Solution

%Discriminant Equation.

Discriminant=b^2-4*a*c;

%Check if it is real or imaginary roots.
if(Discriminant>0)
disp('Roots are Real');
elseif(Discriminant==0)
disp('Roots are Real and Equal');
else
disp('Roots are Imaginery');
end

%Roots of the equation are:
x1= (-b + sqrt(Discriminant))/(2*a);
x2= (-b - sqrt(Discriminant))/(2*a);

%Result
disp('The roots of the equation are:');
fprintf('x1= (%f) +i (%f) ', real(x1), imag(x1));
fprintf('x2= (%f) +i (%f) ', real(x2), imag(x2));

b)

[x1,x2]=quadroots(1,-10.^5,1);
[x3,x4]=quadroots(1,10.^5,1);
backward_error_1=x1.^2-10.^5.*x1+1;
backward_error_2=x2.^2-10.^5.*x2+1;
backward_error_3=x3.^2-10.^5.*x3+1;
backward_error_4=x4.^2-10.^5.*x4+1;

%Print backward errors.
fprintf('Backward Error 1 of 1st root 1st equation:%f ', real(abs(backward_error_1)));
fprintf('Backward Error 2 of 2nd root 1st equation:%f ', real(abs(backward_error_2)));
fprintf('Backward Error 3 of 1st root 2nd equation:%f ', real(abs(backward_error_3)));
fprintf('Backward Error 4 of 2nd root 2nd equation:%f ', real(abs(backward_error_4)));

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