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)
댓글 수: 1
Walter Roberson
2015년 7월 8일
What difficulty are you encountering?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!