Solve the system:
x + ⌊y⌋ + {z} = 3.141
⌊x⌋ + {y} + z = 2.718
{x} + y + ⌊z⌋ = 1.618
Where ⌊p⌋ is the floor function and {p} is the fractional part function.
syms xf yf zf
for x=0:3
xi=sym(x);
for y=0:3
yi=sym(y);
for z=0:3
zi=sym(z);
eq1=xi+xf+yi+zf==3.141;
eq2=xi+yf+zi+zf==2.718;
eq3=xf+yi+yf+zi==1.618;
a=solve([eq1,eq2,eq3],xf,yf,zf);
if abs(eval(a.xf))<1 && abs(eval(a.yf))<1 && abs(eval(a.zf))<1
disp( [eval(xi+a.xf),eval(yi+a.yf),eval(zi+a.zf)] )
% fprintf('\n')
end
end
end
end
tries all integer parts of x, y and z from zero through 3, and treats the fractional parts xf, yf and zf as the three unknowns in the three equations.
Found are these sets:
x y z
2.0205 1.5975 0.1205
2.0205 0.5975 1.1205 ?? fails second eq
1.0205 2.5975 0.1205 ?? fails second eq
1.0205 1.5975 1.1205 ?? fails first eq
3.0205 1.5975 -0.8795 *
3.0205 0.5975 0.1205 ?? fails second eq
2.0205 2.5975 -0.8795 *
2.0205 1.5975 0.1205 same as first row
Those with an asterisk are incorrect for the last equation, as the floor of z is actually -1 in those sets, but was treated as zero in the calculation.
The questionable ones probably result from negative fractianal parts added to the wrong integral parts.
Indeed, adding the appropriate check:
if abs(eval(a.xf))<1 && abs(eval(a.yf))<1 && abs(eval(a.zf))<1 ...
&& eval(a.xf)>0 && eval(a.yf)>0 && eval(a.zf)>0
disp( [eval(xi+a.xf),eval(yi+a.yf),eval(zi+a.zf)] )
does indeed result in the program showing only that one line.
That's
x = 2.0205; y = 1.5975; z= 0.1205
|
Posted by Charlie
on 2022-09-18 08:57:01 |