MatLab-可变精度算法 [英] MatLab - variable precision arithmetic

查看:124
本文介绍了MatLab-可变精度算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的问题,关于vpa命令,该命令可用于评估MatLab中的符号表达式.

I have a brief question regarding the vpa command one may use to evaluate symbolic expressions in MatLab.

我的教科书上说:

在数字上使用诸如sqrt之类的功能时,请务必小心,默认情况下会产生双精度浮点数.您需要将此类输入作为符号字符串传递给vpa正确的评估:vpa('sqrt(5)/pi')."

"You need to be careful when you use functions such as sqrt on numbers, which by default result in a double-precision floating-point number. You need to pass such input to vpa as a symbolic string for correct evaluation: vpa('sqrt(5)/pi')."

我不太理解这里的行话.为什么对于大多数输入我键入vpa(input)vpa('input')都得到完全相同的答案,而对平方根却没有?例如,如果我键入vpa(sin(pi/4))vpa('sin(pi/4)'),我得到的答案完全相同,但是如果我将上面的给定问题键入为vpa(sqrt(5)/pi),则得到的答案将与我键入vpa('sqrt(5)/pi')时得到的答案不同.

I don't quite understand the jargon here. Why is it that for most inputs I get the exact same answer whether I type vpa(input) or vpa('input'), but not for square roots? For instance, if I type vpa(sin(pi/4)) or vpa('sin(pi/4)'), I get the exact same answers, but if I type the give problem above as vpa(sqrt(5)/pi), I do not get the same answer as when I type vpa('sqrt(5)/pi').

如果有人能比我的书更详细地解释这一点,我将不胜感激!

If someone could explain this in a little more detail than what my book does above, I would be very grateful!

推荐答案

我不是MatLab专家,但是没有引号,您正在将sqrt(5)/pi结果传递到vpa()中:

I'm no MatLab expert, but without quotes, you're passing the result of sqrt(5)/pi into vpa():

  vpa(sqrt(5)/pi)
= vpa(0.7117625434171772)

用引号引起来,您要将表达式 sqrt(5)/pi(未经评估并以精确形式)传递到vpa()中,然后告诉MatLab以可变的精度计算sqrt(5)/pi.

With quotes, you're passing the expression sqrt(5)/pi (unevaluated and in exact form) into vpa() and then telling MatLab to compute sqrt(5)/pi with variable precision.

这篇关于MatLab-可变精度算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆