Write Tabular Data to Text File Write a short table of the exponential function to a text file called exp.txt.

조회 수: 1 (최근 30일)
A = input('Enter A: ');
B = input('Enter B: ');
func = @(x) exp(x)-2*cos(x);
e = 1;
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,'%6s %12s\r\n','A','B','C','e');
end
  댓글 수: 4

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 6일
편집: Azzi Abdelmalek 2015년 7월 7일
Edit
A = input('Enter A: ');
B = input('Enter B: ');
func = @(x) exp(x)-2*cos(x);
e = 1;
fileID=fopen('fic.txt','w')
fprintf(fileID,'%s \t %s\t %s\t %s \r\n','i','m','f(m)','error');
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)

카테고리

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