% 注释的地方需要修改
clear
xtrue=3.14159235; % 真实值
x=3.1415; % 近似值
err=xtrue-x;
[~,m]=enotation(x);
[err,q]=enotation(err);
if err<5
n=m-q
else
n=m-q-1
end
e=sym(1/2)*10^(m-n)
function [x,m]=enotation(x)
x=abs(x);
p=0;
while x>=10
x=x/10;
p=p+1;
end
if x~=0
while x<1
x=x*10;
p=p-1;
end
end
m=p+1;
end