Using Matlab Write a while loop that computes and prints the
Using Matlab. Write a while loop that computes and prints the value X^2 where X = 1,2,3,4,5,.... Your loop should terminate when the calculated value of X^2 is less than 0.001. Do not use a break statement.
Solution
main.m
clc;
close all;
clear all;
x=0;
y=x.^-2;
while y>0.001
x=x+1;
y=x.^-2;
disp(y)
end
Output :
1
0.2500
0.1111
0.0625
0.0400
0.0278
0.0204
0.0156
0.0123
0.0100
0.0083
0.0069
0.0059
0.0051
0.0044
0.0039
0.0035
0.0031
0.0028
0.0025
0.0023
0.0021
0.0019
0.0017
0.0016
0.0015
0.0014
0.0013
0.0012
0.0011
0.0010
9.7656e-004

