The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problem in complex number calculation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

modimh

India
4 Posts

Posted - 07/01/2002 :  03:19:07 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have written a programme using OriginC. I need to calculate exponential value of complex numbers. The exponential function available in complex.h file didnot give me correct value of my complex numbers. for example my OriginC function contains following:


complex a,b;
a=1+2i;
b=exp(a);
printf("%e",cabs(b));

here irrespective of value 'a' the output remains same. Please help me

easwar

USA
1965 Posts

Posted - 07/01/2002 :  09:43:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

For the sequence of operations you are doing, the result should depend only on the real part of a.

a=p+iq
b=exp(p+iq) = exp(p)* exp(iq)
conjgate of b, b* = exp(p) * exp(-iq)
cabs(b) = sqrt(b x b*) = sqrt(exp(2p)) = exp(p)


Easwar
OriginLab.


Edited by - easwar on 07/01/2002 09:48:17
Go to Top of Page

modimh

India
4 Posts

Posted - 07/04/2002 :  04:20:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Dr. Easwar
Thank you very much for reply. I have analysed the problen in my programme. Actually when i was multiplying complex defined array with double defined array and inputting this to exponential function than the output was remainning same=(1+0i) irrespective of input values. I have used following scheme to solve the problem

vector M(10), N(10);
vector d(10);

N[j]=exp(M[j]*d[j]); //this way the result was remainning same irrespective of input parameters values.
So I have defined another temperary variable
and stored d[j] in that i.e.

double temp;
temp=d[j];
now
N[j]=exp(M[j]*temp);

This way the value of N[j] is changing as input values changing. If there is another better way to do it please suggest.
My OriginC function is working well. I want to include it in non-linear fitting functions list. Can I do it Please suggest.
Regards
M.H.Modi
quote:

Hi,

For the sequence of operations you are doing, the result should depend only on the real part of a.

a=p+iq
b=exp(p+iq) = exp(p)* exp(iq)
conjgate of b, b* = exp(p) * exp(-iq)
cabs(b) = sqrt(b x b*) = sqrt(exp(2p)) = exp(p)


Easwar
OriginLab.


Edited by - easwar on 07/01/2002 09:48:17

Go to Top of Page

modimh

India
4 Posts

Posted - 07/04/2002 :  08:50:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The two vector defined M[j], N[j] is of type complex. And other d[j] is of type double. I had typed but surprisingly it is not being shown on screen

vector M(10), N(10);//complex type
vector d(10);// double type


M.H.Modi


Go to Top of Page

easwar

USA
1965 Posts

Posted - 07/04/2002 :  2:21:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

...If there is another better way to do it please suggest.
...My OriginC function is working well. I want to include it in non-linear fitting functions list.



Hello,

We need to fix the problem with product of complex and real vectors. The workaround you are using is good.

As for using your Origin C function to perform fitting, you can look at the sample project:
..\Sample Projects\Programming\NLSF User-defined Function\AsymGauss.opj
to see how you can define and add a new fitting function that uses an Origin C function.

You can also type the Origin C code right inside the function. Please review the following sample project for an example:
..\Sample Projects\Data Analysis\Curve Fitting\NLSF User Def Func.opj

Easwar
OriginLab.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000