c语言 单词变复数,用C语言声明复数

Hi All,

I have a matlab program in which i have to calculate values of an expression containing complex numbers.

I have to convert the same program to C language so as to calculate the enegry estimate using another software.

Now the bone of contention here for me is how can i change the complex number expression in MATLAB to that of the equivalent in C .

Please help, in case one needs i can put the expression here as well.

Thanks,

Chandra.

解决方案Poorly speaking, complex numbers are just an ordered pair of real ones, following certain rules. Hence you may code them this way:

typedef struct tagComplex

{

double re; //real part

double im; //imaginary part

} Complex;

Then you may define the functions acting on them (and enabling you to solve expressions).

For instance,

setu.dixit19 wrote:Qen[n1]=exp(j*(n1-1)*(vv0[k]-vv0[l]))

It looks you need the complex exp function

void complex_exp(Complex * pOperand, Complex * pResult)

{

double er = exp(pOperand->re);

pResult->re = er * cos( pOperand->im);

pResult->im = er * sin( pOperand->im);

}

The most basic way would be to create a struct defining each component of the number. Assuming you are only working in 1 dimension then your complex number will be of the form ai+b, and so your struct would look like

typedef struct {

float a; //The "imaginary" part. Might be a int instead

float b; //The real part. Might be a int instead

} ComplexNumber;

Could you please provide the equation and indicate weather it needs to work on other similar equations or only this exact one and the operations that you are wanting to perform.

If it is a relatively simple equation like sqrt(-1) then there can be a simple answer without having to implement a complex numbers system.

ComplexNumber ComplexSqrt(float nNumber) {

ComplexNumber cnRes = { 0, 0 };

if (nNumber < 0) { //nNumber is negative. Result will be complex

cnRes.a = sqrt(-nNumber);

} else { //nNumber is positive. Result will be real

cnRes.b = sqrt(nNumber);

}

return cnRes;

}

Thanks Andrew for your response.

However the equation that i am reffering to as given below:

"Qen[n1]=exp(j*(n1-1)*(vv0[k]-vv0[l]))"

This expression is the one that i need to calculate and the concern is how to remove the ''j'' part from the equation.

Looking forward to your further replies ..

cheers

Setu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值