Chapter 5
5.1 Determine the real roots of f (x) = −0.6x2 + 2.4x + 5.5:
(a) Graphically.
(b) Using the quadratic formula.
(c) Using three iterations of the bisection method to determine
the highest root. Employ initial guesses of xl = 5 and xu = 10.
Compute the estimated error εa and the true error εt after each
iteration.
a) it appears to be -1.5 and 5.5
x = -3:.1:7;
y = -0.6.*x.^2 + 2.4.*x + 5.5;
plot(x,y, x, 0)
excel:
The formula I used is at the top of the picture below, right after Fx.
b) I wrote a program to do this:
public static void main(String[] args) {
quad(-0.6, 2.4, 5.5);
}
public static void quad(double a, double b, double c){
double tom = (b * b - 4 * a * c);
double real = -b / (2 * a);
if (tom >= 0) {
System.out.println(Math.sqrt(tom) / (2 * a) + real);
System.out.println(-Math.sqrt(tom) / (2 * a) + real);
} else {
System.out.println(real + " + " + (Math.sqrt(-tom) / (2 * a)) + "i");
System.out.println(real + " - " + (Math.sqrt(-tom) / (2 * a)) + "i");
}
}
-1.6285901761795403
5.62859017617954
in matlab:
function [ output ] = quadr( a,b,c )
output(1) = (sqrt((b * b - 4 * a * c)) / (2 * a) + (-b / (2 * a)));
output(2) = (-sqrt((b * b - 4 * a * c)) / (2 * a) + (-b / (2 * a)));
end
>> quadr(-0.6,2.4,5.5)
ans =
-1.6286 5.6286
c)
f = @(x) -0.6.*x.^2 + 2.4.*x + 5.5;
%first guess
%ps = positive side ; ns = negitive side
f(5) % = 2.5 so ps = 5;
f(10)% = -30.5 so ns = 10;
%the first guess will be 10 - 5 / 2 = 7.5
%we know the root is really at: 5.6286 so the % error is
root = 5.6286;
abs((root - 7.5)/root) * 100
% 33.2481%
f(7.5) % = -10.25 so ns is now = 7.5
% the second guess is going to be 7.5 - 5 / 2 = 6.25
abs((root - 6.25)/root) *100
% 11.04%
f(6.25) % = -2.9375 so ns is now = 6.25
% the third and final guess will be 6.25 - 5 / 2 = 5.625
abs((root - 5.625)/root) *100
% 0.064%
5.2 Determine the real root of f (x) = 4x3 − 6x2 + 7x − 2.3:
(a) Graphically.
(b) Using bisection to locate the root. Employ initial guesses of
xl = 0 and xu = 1 and iterate until the estimated error εa falls
below a level of εs = 10%.
a)
f = @(x) 4.*x.^3 - 6.*x.^2 + 7.*x - 2.3;
x = -.4:.8;
plot(x, f(x), x, 0)
b)
%b)
f(0) % = -2.3 so ns = 0;
f(1) % = 2.7 so ps = 1;
%first guess will be 1 - 0 / 2 = .5
root = 0.450124;
abs((root - .5)/root)*100
% 11.0805%
f(.5) % = .2 so ps = .5 and the second guess will be .5 - 0 / 2 = .25
abs((root - .25)/root)*100
% 44.4597%
f(.25) % = -0.8625 so ns = .25 and the third guess will be .5 - .25 / 2 = 0.3750
abs((root - 0.3750)/root)*100
% 16.6896%
f(0.3750) % = -0.3078 so ns = .375 and the forth guess will be 0.4375
abs((root - 0.4375)/root)*100
% 2.8046% and this is where we stop since its less than 10%
5.3 Determine the real root of f (x) = −26 + 85x − 91x2 +
44x3 − 8x4 + x5 :
(a) Graphically.
(b) Using bisection to determine the root to εs = 10%. Employ initial
guesses of xl = 0.5 and xu = 1.0.
(c) Perform the same computation as in (b) but use the falseposition
method and εs = 0.2 %.
a)
% a)
f = @(x) -26 + 85.*x -91.*x.^2 + 44.*x.^3 - 8.*x.^4 + 5.*x;
x = -.5:.01:1.5;
plot(x, f(x), x, 0)
b)
root = 0.557026;
f(.5) % = -1.2188 so ns = .5
f(1) % = 5 sp ps = 1 which means the first guess is .75
abs((root - .75)/root)*100
% 34.6436%
f(.75) % = 2.8311 so ps = .75 and next guess is 0.6250
abs((root - 0.6250)/root) * 100
% 12.2030%
f(0.6250) % = 1.1950 so ps - .625 and next guess is 0.5625
abs((root - 0.5625)/ root) *100
% 0.9827% so we can stop here because its under 10%