Matlab计算结果不正确

时间:2016-03-04 07:19:34

标签: matlab

我有一些Matlab代码可以玩。但答案不正确:

x = linspace(-pi, pi, 10)

sinc = @(x) sin(x) ./ x

sinc(x) // wrong result occurs at here.

预期结果如下:

ans =

  Columns 1 through 6:

  3.8982e-17   2.6306e-01   5.6425e-01   8.2699e-01   9.7982e-01   9.7982e-01

Columns 7 through 10:

  8.2699e-01   5.6425e-01   2.6306e-01   3.8982e-17

真实结果:

ans =
 Columns 1 through 3
  0.000000000000000   0.263064408273866   0.564253278793615
 Columns 4 through 6
  0.826993343132688   0.979815536051016   0.979815536051016
 Columns 7 through 9
  0.826993343132688   0.564253278793615   0.263064408273866
 Column 10
  0.000000000000000

详细信息:我的操作系统是linux linux,          Matlab是通过官方网站下载的。

matlab版本是2015b

1 个答案:

答案 0 :(得分:2)

就我所见,您呈现的预期结果和实际结果完全相同。

唯一的区别是符号:normal vs scientific 使用format short,您可以切换为scientific表示法,并使用相同的格式获得相同的结果。

相关问题