复数 [英] complex numbers

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

问题描述

有人可以告诉我为什么这不起作用......


-------------------- ---------------------

#include< complex>

using namespace std;

typedef complex< long double> cld;


void main()

{

cld cmplx,temp;

cmplx = cld(-1.0,0.0);

temp = pow(cmplx,0.5);

}

-------- ------------------------------------

-1的平方根是j(或i),但为什么我调试这个代码的温度是

(1,0)。




如果我这样做...

void main()

{

cld cmplx,temp;

cmplx = cld(-1.0,0.0);

temp = pow(cmplx,0.5);

}


我得到了相同的结果。 temp =(1,0)当real为1且虚数是

0.


那么,pow函数有什么问题?为什么我不能使用分数作为

指数? (顺便说一句,我需要找到立方根。这就是为什么我不使用

sqrt(...))

谢谢,Blair

解决方案



" Blair" < BF ******** @ hotmail.com>在消息中写道

news:3f ******** @ 127.0.0.1 ...

有人可以告诉我为什么这不起作用。 ..

---------------------------------------- -
#include< complex>
使用命名空间std;
typedef complex< long double> cld;

void main()
{cld cmplx,temp;
cmplx = cld(-1.0,0.0);
temp = pow( cmplx,0.5);
}
------------------------------------ --------
-1的平方根是j(或i),但为什么我调试这个代码temp给出
as(1,0)。



如果我这样做......
void main()
{cld cmplx,temp;
cmplx = cld(-1.0) ,0.0);
temp = pow(cmplx,0.5);
}
我得到相同的结果。 temp =(1,0)当real为1且虚构的
为0.

那么,pow函数有什么问题?为什么我不能使用分数作为
指数? (顺便说一句,我需要找到立方根。那就是为什么我不使用
sqrt(...))

谢谢,Blair




我的第一个猜测是pow函数(在< cmath>中声明)获得转换为double或float的

第一个参数。


dan


" Blair" < BF ******** @ hotmail.com>在消息中写道

news:3f ******** @ 127.0.0.1 ...

有人可以告诉我为什么这不起作用。 ..

---------------------------------------- -
#include< complex>
使用命名空间std;
typedef complex< long double> cld;

void main()
{cld cmplx,temp;
cmplx = cld(-1.0,0.0);
temp = pow( cmplx,0.5);
}
------------------------------------ --------
-1的平方根是j(或i),但为什么我调试这个代码temp给出
as(1,0)。



如果我这样做......
void main()
{cld cmplx,temp;
cmplx = cld(-1.0) ,0.0);
temp = pow(cmplx,0.5);
}
我得到相同的结果。 temp =(1,0)当real为1且虚构的
为0.

那么,pow函数有什么问题?为什么我不能使用分数作为
指数? (顺便说一句,我需要找到立方根。那就是为什么我不使用
sqrt(...))

谢谢,Blair




尝试


temp = pow(cmplx,0.5L);


- -

Cy
http:// home .rochester.rr.com / cyhome /


" Dan Cernat" < CE **** @ dan.com>写道......


布莱尔 < BF ******** @ hotmail.com>在消息中写道
新闻:3f ******** @ 127.0.0.1 ...

有人可以告诉我为什么这不起作用...

-----------------------------------------
#include< complex>
使用命名空间std;
typedef complex< long double> cld;

void main()
{cld cmplx,temp;
cmplx = cld(-1.0,0.0);
temp = pow( cmplx,0.5);
}
------------------------------------ --------
-1的平方根是j(或i),但为什么我调试这个代码temp是
给出

as

(1,0)。



如果我这样做...
void main()
{
cld cmplx,temp;
cmplx = cld(-1.0,0.0);
temp = pow(cmplx,0.5);
}

我也一样结果。 temp =(1,0)当real为1且虚数


0.

那么,pow有什么问题功能?为什么我不能使用分数



指数? (顺便说一句,我需要找到立方根。那就是为什么我不使用
sqrt(...))

谢谢,Blair



我的第一个猜测是pow函数(在< cmath>中声明)获得转换为double或float的
第一个参数。




< cmath>不包括在内且<复杂>声明它自己的''std :: pow''(和

实际上是其中的四个)。


得到第二个猜测? :-)


我的第一个猜测是''无效主'导致它。


开个玩笑。实际上,正如我通过尝试找到的那样,将其更改为


temp = pow(cmplx,cld(0.5,0));


给出正确的结果。为什么会发生这种情况,我不能说,为了让我的大脑紧张,现在已经太晚了。


Victor


could someone PLEASE tell me why this doesn''t work...

-----------------------------------------
#include <complex>
using namespace std;
typedef complex<long double> cld;

void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}
--------------------------------------------
the square root of -1 is j (or i) but why I debug this code temp is given as
(1,0).

or

if I do this...
void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}

I get the same results. temp=(1, 0) when the real is 1 and the imaginary is
0.

So, what is wrong with the pow function? Why can''t I use fractions as the
exponent? (BTW, I need to find cube-roots. That''s why I''m not using
sqrt(...) )
Thanks, Blair

解决方案


"Blair" <bf********@hotmail.com> wrote in message
news:3f********@127.0.0.1...

could someone PLEASE tell me why this doesn''t work...

-----------------------------------------
#include <complex>
using namespace std;
typedef complex<long double> cld;

void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}
--------------------------------------------
the square root of -1 is j (or i) but why I debug this code temp is given as (1,0).

or

if I do this...
void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}

I get the same results. temp=(1, 0) when the real is 1 and the imaginary is 0.

So, what is wrong with the pow function? Why can''t I use fractions as the
exponent? (BTW, I need to find cube-roots. That''s why I''m not using
sqrt(...) )
Thanks, Blair



my first guess is that pow function (as is declared in <cmath>) gets the
first argument converted to a double or float.

dan


"Blair" <bf********@hotmail.com> wrote in message
news:3f********@127.0.0.1...

could someone PLEASE tell me why this doesn''t work...

-----------------------------------------
#include <complex>
using namespace std;
typedef complex<long double> cld;

void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}
--------------------------------------------
the square root of -1 is j (or i) but why I debug this code temp is given as (1,0).

or

if I do this...
void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}

I get the same results. temp=(1, 0) when the real is 1 and the imaginary is 0.

So, what is wrong with the pow function? Why can''t I use fractions as the
exponent? (BTW, I need to find cube-roots. That''s why I''m not using
sqrt(...) )
Thanks, Blair



Try

temp = pow(cmplx, 0.5L);

--
Cy
http://home.rochester.rr.com/cyhome/


"Dan Cernat" <ce****@dan.com> wrote...


"Blair" <bf********@hotmail.com> wrote in message
news:3f********@127.0.0.1...

could someone PLEASE tell me why this doesn''t work...

-----------------------------------------
#include <complex>
using namespace std;
typedef complex<long double> cld;

void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}
--------------------------------------------
the square root of -1 is j (or i) but why I debug this code temp is given

as

(1,0).

or

if I do this...
void main()
{
cld cmplx, temp;
cmplx = cld(-1.0, 0.0);
temp = pow(cmplx, 0.5);
}

I get the same results. temp=(1, 0) when the real is 1 and the imaginary


is

0.

So, what is wrong with the pow function? Why can''t I use fractions as


the exponent? (BTW, I need to find cube-roots. That''s why I''m not using
sqrt(...) )
Thanks, Blair



my first guess is that pow function (as is declared in <cmath>) gets the
first argument converted to a double or float.



<cmath> is not included and <complex> declares its own ''std::pow'' (and
actually the whole four of them).

Got a second guess? :-)

My first guess is that ''void main'' causes it.

Just kidding. Actually, as I found by trying, changing it to

temp = pow(cmplx, cld(0.5, 0));

gives the right result. Why it happens, I can''t say, it''s too late
here for me to strain my brain :-[

Victor


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

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