Note: • Use MATLAB to solve all of the tasks. • For each task, TOL is the requir
ID: 3870875 • Letter: N
Question
Note: • Use MATLAB to solve all of the tasks. • For each task, TOL is the required tolerance, and Nmax is the maximum number of iterations allowed. • You must print if the function executed successfully or not, where success is defined as TOL being satisfied at or before Nmax. • Your function must print the values of pn and f(pn) at each iteration n. • Each MATLAB function must be saved as a separate ‘.m’ file. • Use format long to print numbers with a higher number of decimal places.
Please do not give me incorrect or incomplete code.
Task 1 Given a continuous function f on the interval [a, b] where f(a) and f(b) have opposite signs, implement the Bisection method as a MATLAB function bisection(f, a, b, TOL, Nmax) to find a solution to the equation f(x) = 0, where f is an inline function; a and b are the lower and upper bounds, respectively, of the given interval;
Task 2 Implement the Fixed-Point Iteration method as a MATLAB function fixedPt(g, p0, TOL, Nmax) to find a solution to the equation p = g(p), where g is an inline function; p0 is an initial estimate
Task 3 Implement the Newton’s method as a MATLAB function newton(f, p0, TOL, Nmax) to find a solution to the equation f(x) = 0, where f is an inline function; p0 is an initial estimate. Hint: given an inline function f, the command diff(sym(f)) returns the derivative of f as an inline function.
Task 4 Implement the Secant method as a MATLAB function, secant(f, p0, p1, TOL, Nmax), to find a solution to the equation f(x) = 0, where f is an inline function; p0, p1 are initial approximations.
Task 5 Given a continuous function f on the interval [p0, p1] where f(p0) and f(p1) have opposite signs, implement the false position method as a MATLAB function falsePos(f, p0, p1, TOL, Nmax) to find a solution to the equation f(x) = 0, where f is an inline function; p0, p1 are initial approximations.
Task 6 Use the Fixed-Point iteration method fixedPt(g, p0, TOL, Nmax) to solve a) x = 0.5(sin(x) – cos(x)) b) x = 6 –x For both equations, use p0 = 0.5, TOL = 10–8 , Nmax = 80.
Task 7 Let f(x) = tan(x) – 6. Solve f(x) = 0 using a) bisection(f, a, b, TOL, Nmax) with a = 0, b = 0.48 b) newton(f, p0, TOL, Nmax) with p0 = 0.2 c) secant(f, p0, p1, TOL, Nmax) with p0 = 0, p1 = 0.48 d) falsePos(f, p0, p1, TOL, Nmax) with p0 = 0, p1 = 0.48 Use TOL = 10–10 , Nmax = 100 in all four methods. Which method uses the least amount of iterations to satisfy the tolerance?
Task 8 Let f(x) = 230x 4 + 18x 3 + 9x 2 – 221x – 9. Solve f(x) = 0 using a) bisection(f, a, b, TOL, Nmax) with a = -1, b = 0 b) newton(f, p0, TOL, Nmax) with p0 = -0.5 c) secant(f, p0, p1, TOL, Nmax) with p0 = -1, p1 = 0 d) falsePos(f, p0, p1, TOL, Nmax) with p0 = -1, p1 = 0 Use TOL = 10–15 , Nmax = 100 in all four methods. Which method uses the least amount of iterations to satisfy the tolerance?
Explanation / Answer
Task 1
Task 2
Task 3
function [ x, ex ] = newton( f, df, x0, tol, nmax )
Task 4
function [p1,err,k,y]=secant(f,p0,p1,delta,epsilon,max1)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.