Write Tabular Data to Text File Write a short table of the exponential function to a text file called exp.txt.
Show older comments
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 Comments
James Tursa
on 6 Jul 2015
What is your question?
Angkhana Noyhiran
on 7 Jul 2015
Edited: Azzi Abdelmalek
on 7 Jul 2015
Azzi Abdelmalek
on 7 Jul 2015
Angkhana, please edit your original question.
Azzi Abdelmalek
on 7 Jul 2015
Look at edited answer
Answers (1)
Azzi Abdelmalek
on 6 Jul 2015
Edited: Azzi Abdelmalek
on 7 Jul 2015
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)
Categories
Find more on Data Import and Analysis 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!