X root操作员帮助 [英] X root Operator help

查看:75
本文介绍了X root操作员帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在是Python的新手,我还没能找到

运算符/数学函数来查找平方根甚至是x的根。

号码。我正在重写我在BASIC中编写的一个程序,该程序执行二次方程式(用户输入a,b和c值)的

数学和

告诉用户是否有1个根,2个根或没有真正的根和

显示根,如果它有真正的根。


提前谢谢,

Dan

解决方案

lucidparadox写道:


我现在是Python的新手,我还没能找到

运算符/数学函数来查找平方根甚至是x的根。

号码。



如果没有使用它,我会猜测

它是数学模块中的sqrt函数。


(可能也有兴趣:在同一个模块中的战俘功能



TJG


lucidparadox写道:


我现在是Python新手,我还没找到

运算符/ math函数用于查找

数的平方根或甚至x根。



对于平方根,请使用math.sqrt(y)


对于x root使用y **(1 / x )


我正在重写我在BASIC中编写的程序,该程序执行二次方程式的数学计算(用户放入,b和c值)和

告诉用户它是否有1个根,2个根,或者没有真正的根。

显示根,如果它有真正的根。



在浮点运算中,计算两个根的天真方式

总是使用公式(-b +/- sqrt(b *) * 2 - 4 * a * c))/ 2 * a有时会给你

不准确的结果。参见

< http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/>。


更好的公式,看看如何定义r_1和r_2

< http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula>。

-

Michael Hoffman


4月18日上午8:52,Michael Hoffman< cam.ac ... @ mh391.invalidwrote:
< blockquote class =post_quotes>
lucidparadox写道:


我现在是Python新手,我还没找到

运算符/数学函数,用于查找

数的平方根或甚至x根。



对于平方根,请使用math.sqrt(y)


对于x root使用y **(1 / x )


我正在重写我在BASIC中编写的程序,该程序执行二次方程式的数学计算(用户放入,b和c值)和

告诉用户它是否有1个根,2个根,或者没有真正的根。

显示根,如果它有真正的根。



在浮点运算中,计算两个根的天真方式

总是使用公式(-b +/- sqrt(b *) * 2 - 4 * a * c))/ 2 * a有时会给你

不准确的结果。参见

< http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/>。


更好的公式,看看如何定义r_1和r_2

< http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula>。

-

Michael Hoffman



谢谢。截至目前,我只是想让自己熟悉Python的语法。其实我应该想到y **(1 / x)。

我现在是大学新生所以替代公式没有引入
对我来说谢谢你的指示。


Dan Collins


I''m currently new to Python and I haven''t been able to find the
operator/math function to find the square root or even the x root of a
number. I''m rewriting a program that I wrote in BASIC that does the
math of a quadratic equation (user puts in a, b, and c values) and
tells the user whether it has 1 root, 2 roots, or no real roots and
displays the roots if it has real roots.

Thanks in advance,
Dan

解决方案

lucidparadox wrote:

I''m currently new to Python and I haven''t been able to find the
operator/math function to find the square root or even the x root of a
number.

Without ever having used it, I would guess
it''s the sqrt function in the math module.

(Possibly also of interest: the pow function
in that same module)
TJG


lucidparadox wrote:

I''m currently new to Python and I haven''t been able to find the
operator/math function to find the square root or even the x root of a
number.

For square root, use math.sqrt(y)

For x root use y**(1/x)

I''m rewriting a program that I wrote in BASIC that does the
math of a quadratic equation (user puts in a, b, and c values) and
tells the user whether it has 1 root, 2 roots, or no real roots and
displays the roots if it has real roots.

In floating point arithmetic, the naive way of calculating both roots
always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you
inaccurate results sometimes. See
<http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/>.

For a better formula, see how r_1 and r_2 are defined in
<http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula>.
--
Michael Hoffman


On Apr 18, 8:52 am, Michael Hoffman <cam.ac...@mh391.invalidwrote:

lucidparadox wrote:

I''m currently new to Python and I haven''t been able to find the
operator/math function to find the square root or even the x root of a
number.


For square root, use math.sqrt(y)

For x root use y**(1/x)

I''m rewriting a program that I wrote in BASIC that does the
math of a quadratic equation (user puts in a, b, and c values) and
tells the user whether it has 1 root, 2 roots, or no real roots and
displays the roots if it has real roots.


In floating point arithmetic, the naive way of calculating both roots
always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you
inaccurate results sometimes. See
<http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/>.

For a better formula, see how r_1 and r_2 are defined in
<http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula>.
--
Michael Hoffman

Thanks. As of right now I''m just trying to familiarize myself with
the syntax of Python. Actually I should have thought of y**(1/x).
I''m currently a freshman in college so the alternative formula hasn''t
been introduced to me yet. Thanks for the pointers though.

Dan Collins


这篇关于X root操作员帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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