开发者

MATLAB result is inappropriate

I'm new in MATLAB, i cannot get the answer in the format that i want. I have a basic fun开发者_Python百科ction call, but every execution of the program gives the result in the following format :

357341279027200000/23794118819840001

It's supposed to be in decimal, for example for same execution : 15.0181.

I could not figure out why this is happening ? Can you help me, thank you !!


Type format long on the command prompt or in your script.

If that doesnt work because the value is too large, try using vpa


Note that it's just visual, internally the value computed is precise.

>d  = 357341279027200000/23794118819840001
d =
   15.0181
>> d * 23794118819840001 == 357341279027200000
ans =
     1
>> 15.0181 * 23794118819840001 == 357341279027200000
ans =
     0


Are you sure that you are not using format rat (rational). This is the reason why you may be having fractional values. If you want decimals, try format long or format long g (Long g provides the optimal length and accuracy as a decimal, up to 10 places.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜