Clear Filters
Clear Filters

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

1 view (last 30 days)
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
>>

Answers (1)

dpb
dpb on 24 Jan 2017
>> 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.

Categories

Find more on Historical Contests in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!