semilogy
, semilogx
, loglog
) often make it easier to interpret convergence curves.fprintf
is very handy. It allows to use C style format strings for your program’s output. It works by first specifying what is to be printed and how. For floating point numbers there are 3 possible formats (in Matlab): %f (floating point as in 1.234 or 0.221), %e (exponent notation as in 1.234e+00 or 2.221e-01) or %g (which lets fprintf
choose between %f and %e). One can also specify: the minimum number of characters to be printed and the number of digits after the period (the radix). For example %10.3f
tells fprintf
to format a floating point number as a float, using 10 characters and with 3 digits after the period. The line feed character is \n. Here is an example:>> a=pi; b=pi/10000; c=pi*100000; >> fprintf('%10.3f %10.3f %10.3f\n',a,b,c) 3.142 0.000 314159.265 >> fprintf('%10.3g %10.3g %10.3g\n',a,b,c) 3.14 0.000314 3.14e+05 >> fprintf('%10.3e %10.3e %10.3e\n',a,b,c) 3.142e+00 3.142e-04 3.142e+05 >> fprintf('a=%10.3e, b=%10.3e c=%10.3e\n',a,b,c) a= 3.142e+00, b= 3.142e-04 c= 3.142e+05
help fprintf
or doc fprintf
for more details.