why matlab2018a gives "vpa(int( exp((t-360​).*[0,1e-1​6,1e-15,1e​-14,1e-13,​1e-12,1e-1​1]) , t, 0,360 ))=[ 360.0, 0, 0, 0, 256.0, 368.0, 360.0]"??

1 次查看(过去 30 天)
Hi all,
Weird the matlab 2018a calculate the below code--
syms t;
vpa(int( exp((t-360).*[0,1e-16,1e-15,1e-14,1e-13,1e-12,1e-11]) , t, 0,360 ))
resulting in
[ 360.0, 0, 0, 0, 256.0, 368.0, 360.0]
Do you guys have expertise helping avoid this happening?
thanks a lot
J
  6 个评论
Ameer Hamza
Ameer Hamza 2018-6-19
I get the following output on R2018a and R2017b.
syms t;
vpa(int( exp((t-360).*[0,1e-16,1e-15,1e-14,1e-13,1e-12,1e-11]) , t, 0,360 ))'
ans =
360.0
359.99999999999352000000000231367
359.99999999993520000000000783383
359.99999999935200000000077761612
359.99999999352000000007775999991
359.99999993520000000777599999918
359.99999935200000077759999930015
Are you sure that you are running exactly the same line?
Jiyuan Liu
Jiyuan Liu 2018-7-11
thanks Ameer, i've got the reason for the earlier error i got-- I put digits(5) (or maybe digits(3)) before these sentences. And after I reset it to 32 or 64, the results are normal again.

请先登录,再进行评论。

采纳的回答

Siwan Yang
Siwan Yang 2018-6-22
Hello Jiyuan,
I couldn’t reproduce your result in both R2018a and R2015a. Here is what I got: [ 360.0, 359.99999999999352000000000231367, 359.99999999993520000000000783383, 359.99999999935200000000077761612, 359.99999999352000000007775999991, 359.99999993520000000777599999918, 359.99999935200000077759999930015]
Please try changing different data type and see if you still have the issue.
Thanks,
Siwan
  1 个评论
Jiyuan Liu
Jiyuan Liu 2018-7-11
thanks Siwan, R2018a and R2015a work both fine. I put digits(5) (or maybe digits(3)) before these sentences, which leads to the weird results.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by