フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by