Readme
Readme
Readme
College of Engineering
Laboratory No. 3
Root Finding
Submitted by:
Section:
BSECE 4A
Page1
Problem/Activity:
Task 4.1: Modify the codes userfn.m and testplotm.m to determine the locations
of the roots of the function f(x)=xsinx between 0 and 10. Use the ginput
command to make sure that you have reasonable estimates of the locations of
the zeros. Notice the code userfn.m as it stands takes two input parameters,
whereas this function does not need any parameters and as such the function
can be changed to only have one input, namely x. You should also make sure
you use a dot in the calculation, since the function will be applied to vectors.
Task 4.2: Given that ex > 0 ∀x show that coshx has no zeros and sinhx has only
one. Consequently comment on the zeros of the function f(x)= coshm xsinhn x
where n,m ∈ N.
Task 4.3: Determine the location of the roots of the polynomial f(x)=𝑥 2 + bx +1 , b
∈ R, giving details of when you expect there to be no real roots, one roots or two
real roots. (Attempt this mathematically but then use MATLAB’s plotting routine
to verify your findings.)
Task 4.4: Consider the function f(x) = sinx + β cosx β∈ R and derive an expression
for the value of the zeros of f(x) mathematically. Use MATLAB to verify your
answer for certain values of β (perhaps using zero and one as a start).
Task 4.5: Modify the code eqn.m (page 112) to determine the zeros of the
function f(x) = 2cosx−sinx between −2π and 2π using the fixed point method.
(You may need to use a plot of the function to identify initial guesses for the
values.)
Task 4.6: Consider, using the fixed point method, the zeros of the function f(x)= 𝑥 2
+ bx +1and the two ways of rewriting the function in the required form as
g(x)=−( 𝑥 2 +1)/b and g(x)=− √−(𝑏𝑥 + 1). Using the results from Task 4.3 state
which method is appropriate (if either) for a given value of b. (Recall we require
|𝑔1 (x)| < 1 for the method to work.)
Page2
Task 4.7: Use the bisection method to determine the zero of the function
f(x)=2𝑥 2 − 𝑥 3 + sinx between one and three. You will need to enter thecodes
bisect.m, mbisect.m and func.m. The code bisect.m does not need
modification: however you need to change func.m to evaluate the function f(x)
at a point x (again remember to use the dots in the correct place). You also
need to change mbisect.m to reflect the fact that we are seeking a zero of the
function defined in func.m in the range 1 to 3.
Task 4.8: Consider the function f(x) = cos3x between 0 and π. Comment on the
bisection method using the ranges [0, π], [0, 7π/8] and finally [π/8, π]. It is not
necessary to write a code to solve this problem; you should sketch the curve
and work out what is likely to happen.
Task 4.9: Using the Newton–Raphson method calculate the roots of the functions
f(x)=x cosx − sinx and g(x)=( 𝑥 3 − x)sinx. These should be done as two separate
calculations. You will need to write two MATLAB functions for each case to
evaluate the function and its derivative. These should be called func.m and
func prime.m so that they can be called from Newton Raphson.m (alternatively
you could change the line in Newton Raphson.m to reflect that you are using
different function names).
Task 4.10: Using the method of False Position find the roots of the function
sin(x−𝑥 3 ) between x =0 and x =6 .
Task 4.11: Using the knowledge that the polynomial p(x)= 𝑥 3 − 4𝑥 2 + 5x − 2 has a
repeated root, determine its location.
Task 4.12: Using the command roots calculate the solutions of the equations
𝑥 3 + 𝑥 2 + x +1 = 0 and −2x + x5 + 𝑥 2 = 4.
Here you need to be careful that the coefficients of the polynomials are entered
correctly as vectors.
Task 4.13: Using the command fzero investigate the roots of the functions xsinx +
cosx, (𝑠𝑖𝑛𝑥)3 − sinx and (𝑥 2 − 4x + 5)/(x−1).
Page3
Task 4.14 (*): The solutions of the differential equation
𝑑2 𝑦 𝑑𝑦 1
𝑥2 + 𝑥 + (𝑥 2
− )𝑦 = 0
𝑑𝑥 2 𝑑𝑥 4
are given by 𝐽1 (𝑥) and 𝑌1 (𝑥), which are called Bessel functions. Using the MATLAB
2 2
Task 4.15 (D): The following codes are designed to find a root of the function
f(x)= x sin x − 𝑥 2 cos x −1 using the Newton–Raphson method
MatLab Script:
Task 4.1: function [value] = userf1.m(x)
value = x.*sin(x);
x = linspace(0,10);
y = feval('userf1.m',x);
plot(x,y)
grid on
Task 4.2:
Task 4.3: b = input('Value of b');
Page4
x = -10:0.1:10;
f = x.^2+b*x+1;
plot(x,f)
Value of b2
Task 4.4:
Task 4.5:
function g = eqn(x)
g = acps(sin(x)/2);
x=-2*pi:0.1:2*pi;
f=acos(sin(x)/2);
plot(x,f)
grid on
Task 4.6:
function g=eqn(x)
b=3;
g = -sqrt(-(b*x+1));
Task 4.7:
function[f]=func(x)
f=2*x.^2-x.^3+sin(x);
mbisect
Task 4.8:
Task 4.9:
x = 0:0.01:4.41;
f = x.*cos(x)-sin(x);
fp = -x.*sin(x);
f
fp
Task 4.10:
guess point 1 :0.8
Page5
guess point 2:1.2
f = x.^3-4*.^2+5*x+2;
fp = 3*x.^2-8*x+5;
fpp = 6*x.^2-8;
Task 4.12:
Task 4.13:
Task 4.14:
Task 4.15:
x=0;
in=x;
f(in) = in.*sin(in)-in.^2.*cos(in)-1;
fp(in) = (in+1)*cos(in)-2.*in.*sin(in);
Observation:
Page6