I need more decimal digits than the default for the values of x ...

1 次查看(过去 30 天)
x=(0);
%format long eng
fprintf(' x \n')
fprintf(' ------------- \n')
fprintf('%20i \n',x)
for i=1:10;
fx=exp(pi*x(i))/3 -1;
fxx=pi*exp(pi*x(i))/3;
fxxx=pi*pi*exp(pi*x(i))/3;
x(i+1)=x(i)-(fx*fxx)/((fxx)^2-fx*fxxx);
end
fprintf('%20i \n',x)
where the results are
x
-------------
0
0
2.122066e-001
3.238555e-001
3.486779e-001
3.496975e-001
3.496992e-001
3.496992e-001
3.496992e-001
3.496992e-001
3.496992e-001
3.496992e-001
>>

回答(1 个)

dpb
dpb 2017-1-24
>> x=(0);
for i=1:10;
fx=exp(pi*x(i))/3 -1;
fxx=pi*exp(pi*x(i))/3;
fxxx=pi*pi*exp(pi*x(i))/3;
x(i+1)=x(i)-(fx*fxx)/((fxx)^2-fx*fxxx);
end
>> for i=1:length(x),fprintf('%2i %18.15f\n',i,x(i)),end
1 0.000000000000000
2 0.212206590789194
3 0.323855476664848
4 0.348677850564320
5 0.349697515885638
6 0.349699152561852
7 0.349699152566060
8 0.349699152566060
9 0.349699152566060
10 0.349699152566060
11 0.349699152566060
>>
doc fprintf % for details on format strings
However,
>> diff(x)==0
ans =
0 0 0 0 0 0 0 1 1 1
>>
indicates the precision of a double isn't sufficient. There's an extended precision package from John D'Errico at File Exchange (I think still there) that might help...I didn't look at the functional form to see if there's anything obvious to be done first.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by