Function y=f0(x)
% Enter an integer from the keyboard. Divide the even number by 2 and the odd number by *3+ 1 until 1.
If x== 1
y = 1;
elseif mod(x,2)==0
x = x/2;
y = F0(x);
elseif mod(x,2)== 1
x = x * 3+ 1;
y = F0(x);
other
X=' input error';
disp(X);
end
2. I use matrix equation to solve the problem directly. The function is F 1 (X 1, X2), where X 1 is the head number and x2 is the foot number.
The function y=f 1(x 1, x2)
%x 1 is the number of heads, and x2 is the number of feet.
a =[ 1 1; 2 4];
a =[x 1; x2];
y = a \ A
3. A formula can solve this problem:
y=abs(x)+abs(x-2)
%abs(x) is a function of finding the absolute value.
Or call this function.
Function y=f2(x)
%y=|x|+|x-2|
y = ABS(x)+ABS(x-2);
PS: The most important thing is that you have to learn by yourself.