Shell 如何计算壳中的求幂和根?

Shell 如何计算壳中的求幂和根?,shell,terminal,calculation,expr,Shell,Terminal,Calculation,Expr,一般来说,我是shell和linux的初学者,这是一个shell算术问题,我不知道用终端写什么来解这三个方程。很抱歉,如果这是一个糟糕的问题,我尝试了echo命令和expr,但它们都是错误的,并且有许多不同的错误,例如,'(',语法错误靠近…,E0F,和许多其他不幸的。我希望有人能给我提供正确的命令。我感谢你的任何帮助。我会记下我使用的终端代码,我知道它们是错误的 $ x=8 $ y=21 $ echo $((2*x**3 + sqrt(y/2)) bash: unexpected EOF wh

一般来说,我是shell和linux的初学者,这是一个shell算术问题,我不知道用终端写什么来解这三个方程。很抱歉,如果这是一个糟糕的问题,我尝试了echo命令和
expr
,但它们都是错误的,并且有许多不同的错误,例如,'(',语法错误靠近…,E0F,和许多其他不幸的。我希望有人能给我提供正确的命令。我感谢你的任何帮助。我会记下我使用的终端代码,我知道它们是错误的

$ x=8
$ y=21
$ echo $((2*x**3 + sqrt(y/2))
bash: unexpected EOF while looking for matching ')'
bash: syntax error: unexpected end of file
$ echo $((2*x**3) + (sqrt(y/2)))
bash: command substitution: line 1: syntax error near unexpected token +'
bash: command substitution: line 1: `(2*x**3) + (sqrt(y/2))'
$ echo $((2*x**3)+(sqrt(y/2))
bash: unexpected EOF while looking for matching )'
bash: syntax error: unexpected end of file
$ echo $((2*x**3)+(sqrt(y/2)))
bash: command substitution: line 1: syntax error near unexpected token +(sqrt(y/2))'
bash: command substitution: line 1: `(2*x**3)+(sqrt(y/2))'
$ echo $((2x**3)+(sqrt(y / 2)))
bash: command substitution: line 1: syntax error near unexpected token +(sqrt(y / 2))'
bash: command substitution: line 1: (2x**3)+(sqrt(y / 2))'

shell不是进行浮点计算的合适工具。它只做整数运算,不提供平方根之类的函数

然而,bc实用程序同时做这两件事。它是一种任意精度的十进制算术语言和计算器

$ bc
>>> scale=5
>>> sqrt(21)
4.58257
>>> scale=19
>>> sqrt(21)
4.5825756949558400065
>>> x=8
>>> y=21
>>> x+5
13
>>> x^2
64
>>> 2*x^2 - sqrt(y/2)
124.7596296507960698846
>>> Type Control-D to exit interactive bc.
$

请务必阅读带有
man bc
的bc手册页,以了解其所有功能和限制。

很抱歉,我忘了写问题,请不要介意。谢谢!Q//如果X=8,Y=21,请找到以下表达式的确切结果:•X^2+Y-5•2X^3+√Y/2•Y^2/(X+5)^2欢迎使用Stack Overflow!请阅读。请不要使用注释来添加问题,而应使用问题本身。在那里,请修复问题。我不相信大多数Shell都内置了
sqrt
。您可以尝试传递到
bc
。但是,您认为
sqrt(21/2)
的确切结果是什么(甚至
sqrt(21)/2
)应该是什么?