【问题标题】:How to get fprintf to display higher precision?如何让 fprintf 显示更高的精度?
【发布时间】:2013-04-25 23:26:25
【问题描述】:

我正在尝试使用以下 fprintf 代码

      n
      m
     fprintf('The minimum value of the modulus of the image of C_r is %d \n\nThe correspoding point is at %d \n\n',m,n)

我得到了结果

  n =

  3.632213809443102 + 3.680287679864827i


m =

   5.170831128945713

The minimum value of the modulus of the image of C_r is 5.170831e+000 

The correspoding point is at        3.632214e+000 

我分别打印了 n 和 m 的值,以显示我希望它们如何显示——我如何让 fprintf 以更高的精度显示数字?我尝试更改 %d 个条款,但无济于事

【问题讨论】:

  • 你为什么使用%d 来处理浮点数?为什么不%f%g
  • 因为老实说,我真的不知道自己在做什么。我翻阅了一本手册,并认为我应该使用 %d。我会试试你的答案看看

标签: matlab printf


【解决方案1】:

怎么样

fprintf( '%.15f\n', m );

打印 15 位数字

【讨论】:

  • 还是把'+i...'这个位剪掉了,是不是要把实部和虚部分别放进去?
  • 似乎没有办法解决它。见this post
  • 也许:fprintf('%.15f + %.15fi\n',real(z),imag(z))
  • 如果您不喜欢看到“0.1 + -0.2i”(加减),您可以使用'%.15f %+.15fi\n' 作为格式字符串
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-09
  • 1970-01-01
  • 2011-07-24
相关资源
最近更新 更多