What does the following code do?
Mostrar comentarios más antiguos
clear all
close all
clc
x= input('Enter initial condition: ')
eps= input('Enter accuracy : ')
Nmax= 1e5
for N=1:Nmax
f= 2*x+exp(x/pi)+sin(pi*x)-20
df= 2+(1/pi)*exp(x/pi)+pi*cos(pi*x)
newx= x-f/df
if abs(newx-x)<=eps
disp(['The solotion is: ',num2str(newx)])
disp(['The number of attempts is: ',num2str(N)])
break
end
x=newx
end
if N==Nmax
disp('There is no solution for the given conditions!')
end
3 comentarios
John D'Errico
el 26 de Dic. de 2022
Talk to the source of the code Asing what uncommented junk code does is difficult to say, especially if we are given no clue as to what it is supposed to do. And, sorry, but this is junk code.
the cyclist
el 26 de Dic. de 2022
What your code will do is give the error message you see in red above (after I formatted your code, and ran it here).
daniel
el 26 de Dic. de 2022
Respuestas (1)
Voss
el 26 de Dic. de 2022
0 votos
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!