In: Mechanical Engineering
Can you rewrite this MATLAB code using a for loop instead of a while 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