Problems with the application of Newton's method

조회 수: 1 (최근 30일)
Aryo Aryanapour
Aryo Aryanapour 2021년 12월 29일
댓글: Aryo Aryanapour 2022년 1월 16일
function [] = newton_raphson(func, diff, x0)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
x = x0;
maxiter = 200;
tol = 10^(-5);
eps = 0.4;
c_s = 5.67*10^(-8);
alpha_k = 4;
s1 = 0.250;
s2 = 0.015;
lamda1 = 0.35;
lamda2 = 22.7;
Tw_1 = 1200;
T_l = 10;
func = @(x) eps * c_s * x^4 + (alpha_k + 1/(s1/lamda1+s2/lamda2)) * x - ((1/(s1/lamda1+s2/lamda2)) * Tw_1 + alpha_k * T_l);
diff = @(x) 4 * eps * c_s * x^3 + (alpha_k + 1/(s1/lamda1+s2/lamda2));
newton_raphson(func, diff, 200)
for i = 1:maxiter
if
diff(x(i)) < tol
fprintf('Pitfall hast occured a better initial guess\n');
return;
end
x(i+1) = x(i) - func(x(i))/diff(x(i));
abs_error(i+1) = abs((x(i+1)-x(i))/x(i+1))*100;
if
abs(x(i+1) - x(ix)) < tol
fprintf('The Root has converged at x = %.10f\n', x(i+1));
else
fprintf('Iteration no: %d,current guess x = %.10f, error = %.5f', i, x(i+1), abs_error(i+1));
end
end
end
Can someone help me please. Unfortunately, I'm not quite fit in Matlab and have recently started working with functions. I don't know what's wrong with this code. Unfortunately I don't get a result. It had to come out with an X value of around 290.
Thanks a lot

채택된 답변

Torsten
Torsten 2021년 12월 29일
편집: Torsten 2021년 12월 29일
function main
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
x0 = 20;
maxiter = 200;
tol = 10^(-5);
eps = 0.4;
c_s = 5.67*10^(-8);
alpha_k = 4;
s1 = 0.250;
s2 = 0.015;
lamda1 = 0.35;
lamda2 = 22.7;
Tw_1 = 1200;
T_l = 10;
func = @(x) eps * c_s * x^4 + (alpha_k + 1/(s1/lamda1+s2/lamda2)) * x - ((1/(s1/lamda1+s2/lamda2)) * Tw_1 + alpha_k * T_l);
diff = @(x) 4 * eps * c_s * x^3 + (alpha_k + 1/(s1/lamda1+s2/lamda2));
xsol = newton_raphson(func, diff, x0)
end
function xsol = newton_raphson(func, diff, x0)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
x(1) = x0;
maxiter = 200;
tol = 10^(-5);
for i = 1:maxiter
if diff(x(i)) < tol
fprintf('Pitfall hast occured a better initial guess\n');
return;
end
x(i+1) = x(i) - func(x(i))/diff(x(i));
abs_error(i+1) = abs((x(i+1)-x(i))/x(i+1))*100;
if abs(x(i+1) - x(i)) < tol
fprintf('The Root has converged at x = %.10f\n', x(i+1));
else
fprintf('Iteration no: %d,current guess x = %.10f, error = %.5f', i, x(i+1), abs_error(i+1));
end
end
xsol = x(end);
end
  댓글 수: 9
Torsten
Torsten 2022년 1월 16일
편집: Torsten 2022년 1월 16일
Sorry, but I'm no engineer. I can't help you in this respect.
I thought the question was how to obtain deduced quantities from the result xsol in general.
Aryo Aryanapour
Aryo Aryanapour 2022년 1월 16일
Thorsten
dont be sorry
You are the best. You have been able to help me a lot more than I thought. Thank you again for always replying so quickly.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by