Borrar filtros
Borrar filtros

Problems with the application of Newton's method

1 visualización (últimos 30 días)
Aryo Aryanapour
Aryo Aryanapour el 29 de Dic. de 2021
Comentada: Aryo Aryanapour el 16 de En. de 2022
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

Respuesta aceptada

Torsten
Torsten el 29 de Dic. de 2021
Editada: Torsten el 29 de Dic. de 2021
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 comentarios
Torsten
Torsten el 16 de En. de 2022
Editada: Torsten el 16 de En. de 2022
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 el 16 de En. de 2022
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by