# Newton-Raphson method

조회 수: 41(최근 30일)
Alexa Fernanda Cantú García 2021년 1월 8일
답변: Monisha Nalluru 2021년 1월 11일
I have the function f(x)=sen(x)-2x^2 with x0=1.1 and iterating until the approximate relative error (Ea) is less than the estimated error Es=0.02%. The exact value of the root is 0.4810 and I need to get the find the percent true relative error (Ev).
This is what i have done, but it doesn't run with the trigonometric function.
%This program is for you to run it, is problem 2 of HW1.
f=@(x) x.^3-(12.1*x.^2)+(45.86*x)-52.976 %f(x) of Problem 2
EE=input("Enter EE__");%your Absolute relative approximated percentage error
vv=input("Enter vv_");%Is the true value, the real known root
nrhw1(f,x0,EE,vv)
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Walter Roberson 2021년 1월 8일
f = @(x) sin(x)-2*x.^2

댓글을 달려면 로그인하십시오.

### 답변(1개)

Monisha Nalluru 2021년 1월 11일
Relative error is used in Newton Raphson method inorder to find whther the root matches the given tolerance.
Relative error can bee found using the following formula relative_error = abs( f(x+1) -f(x)/f(x+1)) * 100
As an example
function [r] = newton(x1)
n = 1000;
tol_error = 0.0002;
r = x1;
for t=1:n
x_plus = x1 - (my_func(x1)/my_func_diff(x1));
relative_error(t) = abs((x_plus - x1)/(x_plus))*100; % calculating relative error
disp(relative_error(t));
fun_val(t) = my_func(x1);
if (relative_error(t) < tol_error) % checking whether relative error is less than tolerance
display(approx_error(t));
r = x_plus;
break;
else
x1 = x_plus;
end
end
end
function y = my_func_diff(x)
y = cos(x)-4*x;
end
function y = my_func(x)
y = sin(x)-2*x^2;
end
Hope this helps!

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by