필터 지우기
필터 지우기

I am unable to understand this. I was trying to solve a non linear eqation with newton raphson and modified newton raphson method. Both methods give different results. Below is my code. can you find the error. Both are separate files.

조회 수: 1 (최근 30일)
%%Newton raphson method
clc
clear all
close all
%%Initial condition
x0 =0.92;
maxiteration = 50;
tolX = 1e-04;
f = @(x) x^2-2*x+1; %function to be solved
%%Computation
x = x0;
xold = x0;
for i = 1:maxiteration;
df = 2*x-2;
x = x-f(x)/df;
err(i) = norm(x-xold);
xold = x;
if (err(i)<tolX)
break;
end
end
msg = ['The solution converged in ', num2str(i),'th iterations.'];
disp(msg)
msg1 = ['converged numerical solution(critical values):'];
disp(msg1)
fprintf('x = %.4f\n',x);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Modified newton Raphson method
clc
clear all
close all
%%Initial condition
x0 =0.92;
maxiteration = 50;
tolX = 1e-04;
f = @(x) x^2-2*x+1;
%%Computation
x = x0;
xold = x0;
for i = 1:maxiteration;
df = 2*x0-2;
x = x-f(x)/df;
err(i) = norm(x-xold);
xold = x;
if (err(i)<tolX)
break;
end
end
msg = ['The solution converged in ', num2str(i),'th iterations.'];
disp(msg)
msg1 = ['converged numerical solution:'];
disp(msg1)
fprintf('x = %.4f\n',x)

답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 24일
df = 2*x0-2;
That is incorrect. You are creating the slope based upon the initial point, not based upon the current point.
  댓글 수: 4
Hrishikesh Das
Hrishikesh Das 2019년 12월 24일
In the modified newton raphson method we have to calculate the slope with respect to the initial value. please comment. thank you.1.PNG
Walter Roberson
Walter Roberson 2019년 12월 24일
Look at your existing code that works. It says
df = 2*x-2;
Now how can you use the ideas there to modify the non-working line,
df = 2*x0-2;

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

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by