How to send to an output file !

2 次查看(过去 30 天)
Fatima Al Marzoqi
Fatima Al Marzoqi 2014-6-27
I create a code, and decide to send an output to a file, but not all the values displayed.
This is the code
x=-1:0.1:1;
a=1+(x.^2)+((x.^4)/2);
b=exp(x.^2);
c=abs(b-a);
y=[x a b c];
fid=fopen('Taylor.exp','w');
disp('X Approx.Values exp(x.^2) Absolute Error')
disp('________________________________________________________________________________________________')
fprintf(fid,'%.1f\t\t%.7f\t\t%.7\t\t%.7f\n',y);
fclose(fid);
please I want the answer as soon as possible!

回答(1 个)

Image Analyst
Image Analyst 2014-6-27
You have a .7 instead of a .7f. I also opened it in write text mode. Try this:
clc;
x=-1:0.1:1;
a=1+(x.^2)+((x.^4)/2);
b=exp(x.^2);
c=abs(b-a);
y=[x a b c];
fid=fopen('Taylor.exp','wt');
fprintf(fid,'X Approx.Values exp(x.^2) Absolute Error\n');
fprintf(fid, '________________________________________________________________________________________________\n');
fprintf(fid, '\n%.1f\t\t%.7f\t\t%.7f\t\t%.7f\n', y);
fclose(fid);
type 'Taylor.exp'

类别

Help CenterFile Exchange 中查找有关 Power and Energy Systems 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by