Something is wrong with my output...
Mostrar comentarios más antiguos
Question:
Create a script that calculates the sine, cosine, and tangent of a vector from 0 to2π with steps of π/16. The numbers should have three digits to the right of the decimal. Determine an appropriate field width. Use fprintf to display the output in tabular format with the following headers.
x sin(x) cos(x) tan(x)
My code:
X = [0:(pi/16):(2*pi)]
a = sin(X);
b = cos(X);
c = tan(X);
fprintf('%6s %6s %6s\n','sin','cos','tan');
fprintf('%.3f \t %.3f \t %.3f\n',a,b,c);
and my output:
sin cos tan
0.000 0.195 0.383
0.556 0.707 0.831
0.924 0.981 1.000
0.981 0.924 0.831
0.707 0.556 0.383
0.195 0.000 -0.195
-0.383 -0.556 -0.707
-0.831 -0.924 -0.981
-1.000 -0.981 -0.924
-0.831 -0.707 -0.556
-0.383 -0.195 -0.000
1.000 0.981 0.924
0.831 0.707 0.556
0.383 0.195 0.000
-0.195 -0.383 -0.556
-0.707 -0.831 -0.924
-0.981 -1.000 -0.981
-0.924 -0.831 -0.707
-0.556 -0.383 -0.195
-0.000 0.195 0.383
0.556 0.707 0.831
0.924 0.981 1.000
0.000 0.199 0.414
0.668 1.000 1.497
2.414 5.027 16331239353195370.000
-5.027 -2.414 -1.497
-1.000 -0.668 -0.414
-0.199 -0.000 0.199
0.414 0.668 1.000
1.497 2.414 5.027
5443746451065123.000 -5.027 -2.414
-1.497 -1.000 -0.668
-0.414 -0.199 -0.000
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!