How do I save the outputs from my 'while loop' into a vector?
Mostrar comentarios más antiguos
Here is my function file:
f=inline('x^3+1/x^2+4*sqrt(x)-10')
x0=input('Input your first guess: ')
relErr=1;
while relErr>0.0005
m1=(f(x0+.001)-f(x0))/.001;
m=x0-(f(x0)/m1);
relErr=abs(m-x0)/abs(x0);
fprintf('%-6.4f ',m)
x0=m;
end
I need to save the outputs for 'm' into a vector called 'Root', and I need to save the outputs for 'relErr' into a vecotr called 'Error'.
Thanks!
Respuestas (1)
Azzi Abdelmalek
el 27 de Feb. de 2013
Editada: Azzi Abdelmalek
el 27 de Feb. de 2013
f=inline('x^3+1/x^2+4*sqrt(x)-10')
x0=input('Input your first guess: ')
relErr=1;
m=[ ];
relErr=[ ];
while relErr>0.0005
m1=(f(x0+.001)-f(x0))/.001;
m(end+1)= x0-(f(x0)/m1);
relErr(end+1)= abs(m-x0)/abs(x0);
fprintf('%-6.4f ',m)
x0=m(end+1);
end
Categorías
Más información sobre Semiconductors and Converters 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!