Can you rewrite this MATLAB code using a while loop instead of a for loop?
%formatting
clc, clear, format compact;
%define variables
k=1;
b=-2;
x=-1;
y=-2;
%while loop initialization
for k <= 3
disp([num2str(k), ' ',num2str(b),' ',num2str(x),'
',num2str(y),]);
y = x^2 -3;
if y< b
b = y;
end
x = x+1;
k = k+1;
end
%formatting
clc, clear, format compact;
%define variables
k=1;
b=-2;
x=-1;
y=-2;
%while loop initialization
while k <= 3
disp([num2str(k), ' ',num2str(b),' ',num2str(x),'
',num2str(y),]);
y = x^2 -3;
if y< b
b = y;
end
x = x+1;
k = k+1;
end
Output is attached below
Get Answers For Free
Most questions answered within 1 hours.