I would like the program to display square like this

I would like the program to display square like this
i A B C e
1 1.500000 3.875000 0.500000
2 1.750000 6.609375 0.250000
3 1.875000 8.216797 0.125000
4 1.937500 9.085693 0.062500
5 1.968750 9.537079 0.031250
6 1.984375 9.767086 0.015625
7 1.992188 9.883178 0.007812
8 1.996094 9.941498 0.003906
9 1.998047 9.970726 0.001953
10 1.999023 9.985357 0.000977
11 1.999512 9.992677 0.000488
12 1.999756 9.996338 0.000244
13 1.999878 9.998169 0.000122
14 1.999939 9.999084 0.000061
15 1.999969 9.999542 0.000031
16 1.999985 9.999771 0.000015
17 1.999992 9.999886 0.000008
18 1.999996 9.999943 0.000004
19 1.999998 9.999971 0.000002
20 1.999999 9.999986 0.000001
A = input('Enter A: ');
B = input('Enter B: ');
func = @(x) exp(x)-2*cos(x);
e = 1;
fileID=fopen('fic.txt','w')
while e>0.0001
display(A)
display(B)
C = (A+B)/2
FC = func(C);
FB = func(B);
if(FC*FB>0)
B = C;
else
A = C;
end
e = (abs((FB-FC)/FB))*100
fprintf(fileID,'%6f %6f %6f %6f\r\n',[A,B,C,e]);
end
fclose(fileID)

 Accepted Answer

Jan
Jan on 8 Jul 2015
Edited: Jan on 8 Jul 2015
All I see at first glance the first column differs from your needs only?
count = 1;
while e>0.0001
...
fprintf(fileID,'%d %.6f %.6f %.6f %.6f\r\n', count, A, B, C, e);
count = count + 1;
end

More Answers (0)

Categories

Asked:

on 7 Jul 2015

Edited:

Jan
on 8 Jul 2015

Community Treasure Hunt

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

Start Hunting!