Need help to debug code
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function [x1] = tutorial1(x0,nMax,tol)
x0 = 1.5;
nMax = 15;
tol = 1e-4;
% for loop acting continously for 15 iterations
for i = 1:nMax
fx0= (x0).^3-3.^(x0)+1;
differentialx0=3.*(x0.^2) - 3.^x0.*log(3);
%function f(x0)respectively
x1 = x0 -fx0./differentialx0;
if abs(x1-x0)<tol
break
end
x0 = x1;
fprintf('Iteration = %d, x0 = %.4f, x1 = %.4f, fx1 = %.4f\n',i,x0,x1);
end
% Sample output code for monitoring (this should be included in your loop structure.
return
1 comentario
Respuestas (1)
KALYAN ACHARJYA
el 2 de Mzo. de 2020
Editada: KALYAN ACHARJYA
el 2 de Mzo. de 2020
#Need help to debug code
There is no coding error.
function [x1]=tutorial1(x0,nMax,tol)
% for loop acting continously for 15 iterations
for i = 1:nMax
fx0= (x0).^3-3.^(x0)+1;
differentialx0=3.*(x0.^2) - 3.^x0.*log(3);
%function f(x0)respectively
x1 = x0 -fx0./differentialx0;
if abs(x1-x0)<tol
break
end
x0 = x1;
fprintf('Iteration = %d, x0 = %.4f, x1 = %.4f, fx1 = %.4f\n',i,x0,x1);
end
% Your code as per definition/requirements
end
Save the function as Matlab function file "tutorial1.m" and call it from command promt or a other main script. Please note during call you have to pass the input arguments, as specified in the function file.
>> y=tutorial1(1.5,15,1e-4)
0 comentarios
Ver también
Categorías
Más información sobre Labels and Annotations 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!