Employ the NewtonRaphson method to determine a real root for

Employ the Newton-Raphson method to determine a real root for f(x) = 0.5x^3 - 4x^2 + 6x - 2, using an initial guess of 4.5, and 4.43 Use a Matlab program to solve this (publish in .html), use either function passing or a nest function.

Solution

Main Program File :

% Solve a non-linear equation using Newton-Raphson method
% Main Script File
clc;
clear all;
close all;
x = 4.5;
x_old = 100;
x_true = 4.512;
x = nraphson( x_old,x_true,x );
disp(\'The root is: \');
disp(x);

% Plotting
x = -10:0.01:10;
f = 0.5*x.^3 - 4*x.^2 + 6*x -2;
figure;
plot(f)
grid on;

Function file :

function [ x ] = nraphson( x_old,x_true,x )
%Function for Newton-Raphson method

iter = 0;
while abs(x_old-x) > 10^-3 && x ~= 0
x_old = x;
x = x - (0.5*x^3 - 4*x^2 + 6*x -2)/(1.5*x^2 - 8*x + 6);
iter = iter + 1;
fprintf(\'Iteration %d: x=%.20f, err=%.20f\ \', iter, x, x_true-x);
end

end

Output :

If initital guess is 4.5 then real root of the given equation is 6.1563

If initital guess is 4.43 then real root of the given equation is 0.4746

 Employ the Newton-Raphson method to determine a real root for f(x) = 0.5x^3 - 4x^2 + 6x - 2, using an initial guess of 4.5, and 4.43 Use a Matlab program to so

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site