Question

In: Advanced Math

Matlab Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5...

Matlab

Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5 to find an approximation to a root with tolerance TOL = 0.01. (b) Use secant method with p_0 = 0.5 , p_1 =1.5, to answer same question as (a). (c) Use Method of False position with initial approximate roots as in (b).

Solutions

Expert Solution

MATLAB Script:

close all
clear
clc

syms x
f = x^3 - x; % f(x)
fd = diff(f); % f'(x)
tol = 1e-2;

% Plotting f(x)
xx = -2:0.01:2;
ff = subs(f, xx);
plot(xx,ff), xlabel('x'), ylabel('f(x)'), grid on

ic = 1.5;
[result] = my_newton(f,fd,ic,tol);
fprintf('Solution (Using Newton''s Method): %.8f\n', result)

a = 0.5; b = 1.5;
result = my_secant(f,a,b,tol);
fprintf('Solution (Using Secant Method): %.8f\n', result)

result = my_false_position(f,a,b,tol);
fprintf('Solution (Using False-Position Method): %.8f\n', result)

function [res] = my_newton(func,func_d,ic,tol)
res = ic;
while true
x_ = res;
res = res - subs(func, res)/subs(func_d, res);
if abs(x_ - res) < tol
break;
end
end
end

function xc = my_secant(f,a,b,tol)
x = [a b];
while true
x = [x double((x(end-1)*subs(f,x(end)) - x(end)*subs(f,x(end-1))) / (subs(f,x(end)) - subs(f,x(end-1))))];
if abs(subs(f,x(end))) < tol
break
end
end
xc = double(x(end));
end

function xc = my_false_position(f,a,b,tol)
while true
c = (b*subs(f,a) - a*subs(f,b)) / (subs(f,a) - subs(f,b));
if abs(subs(f,c)) < tol
break
end
if subs(f,a)*subs(f,c) < 0
b = c;
else
a = c;
end
end
xc = double(c);
end

Plot:

Output:

Solution (Using Newton's Method): 1.00000317
Solution (Using Secant Method): 1.00249467
Solution (Using False-Position Method): 0.99736902


Related Solutions

Use matlab to plot Taylor approximation for f(x) for x near 0 Given f(x) = exp(x)...
Use matlab to plot Taylor approximation for f(x) for x near 0 Given f(x) = exp(x) Use subpots to plot and its absolute and realative erros for N= 1,2,3 PLease give matlab code for Taylor and explain in detail, Thank you
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x),...
Use Newton's method to find the absolute maximum value of the function f(x) = 3x cos(x), 0 ≤ x ≤ π; correct to six decimal places.
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2,...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations. Could you please add the copiable Matlab code and the associated screenshots? Thank you!
Optimization Technique: Consider one-variable function f(x). Use Newton Method to find minimum/maximum and plot the graph....
Optimization Technique: Consider one-variable function f(x). Use Newton Method to find minimum/maximum and plot the graph. Use Matlab.
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB....
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB. Find the three roots of the polynomial, i.e, x where f(x) = 0, using Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10−8 .
Practice for Matlab. You can create own f(x). a. Write code to find and plot a...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a root using the modified secant method b. Find the roots using the roots command - identify and plot root of interest c. Use polyder and roots to find and plot the minimum value d. use fminbnd to find and plot minimum value Thank you!
Please show MATLAB code to plot below function from x = −3 to x = 12:...
Please show MATLAB code to plot below function from x = −3 to x = 12: function f = piecewise(x) % implements piecewise function using if statements if x < 0     f = -x^3 - 2*x^2 + 3*x; elseif x <= 8     f = (12/pi) * sin(pi*x/4); else     f = (600*exp(x-8))/(7*(14 + 6*exp(x-8))) -30/7; end
Use​ Newton's method to estimate the solutions of the equation 5 x squared plus x minus...
Use​ Newton's method to estimate the solutions of the equation 5 x squared plus x minus 1=0. Start with x 0 equals negative 1x0=−1 for the left solution and x 0 equals 1x0=1 for the right solution. Find x 2x2 in each case.
Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the...
Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the three roots of the polynomial, i.e, x where f(x) = 0, using: (i) Bisection method, and (ii) Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10^−8 .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT