Iteration output won't show in a plot

1 visualización (últimos 30 días)
Mean der
Mean der el 15 de Oct. de 2020
Comentada: Sudhakar Shinde el 15 de Oct. de 2020
Hello. I created a for loop that will give the approximated values of a square root. My problem is whenever i try to plot the output values, it just simply show an empty graph. Here is my code:
format long;
disp('Number of Iterations Approximate Value')
xData=1;
n=1;
fprintf('\n%d %.12f. \n\n',1,xData)
for n=2:5
x=0.5*(xData+2/xData);
xData=x;
fprintf('\n%d %.12f. \n\n',n,xData)
end
figure
plot(1:1:10,xData)

Respuesta aceptada

Sudhakar Shinde
Sudhakar Shinde el 15 de Oct. de 2020
Try this:
format long;
disp('Number of Iterations Approximate Value')
xData=1;
n=1;
fprintf('\n%d %.12f. \n\n',1,xData)
for n=2:5
x=0.5*(xData(n-1)+2/xData(n-1));
xData(n)=x;
fprintf('\n%d %.12f. \n\n',n,xData)
end
figure
plot(1:1:5,xData)
  2 comentarios
Mean der
Mean der el 15 de Oct. de 2020
Thank you!
Sudhakar Shinde
Sudhakar Shinde el 15 de Oct. de 2020
Welcome. Glad to help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by