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
 All Forums
 Origin Forum
 Origin Forum
 complex number

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
slammu123 Posted - 06/13/2003 : 10:52:56 AM
Hi
I want to add a phase factor i.e exp(ix) in my code.But it says the variable 'i' is not declared.
10   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 06/17/2003 : 1:39:56 PM
I think the complex vector functions GetReal(), GetImaginary() and so on came out in one of the service releases, but I don't recall off hand which one. (The latest is SR4.) If your PC is connected to the internet run Help->Check for Updates and download&install whatever is offered. You'll probably have to run it several times to get caught up.

Alternatively, you can use the non-complex method I suggested in my earlier posts. Namely, replace these lines...

vector<complex> vf; // declare a complex output vector
vf = dx*dy*exp((dA+dB)*1i); // your function
vf.GetReal(dRe); // extract real data
vf.GetImaginary(dIm); // extract imaginary data
vf.GetAmplitude(dAmp); // extract amplitude data
vf.GetPhase(dPh); // extract phase data

with these lines...

dRe = dx*dy*cos(dA+dB);
dIm = dx*dy*sin(dA+dB);
dAmp = abs(dx*dy);
dPh = angle(dRe,dIm);

It's somewhat less efficient but works nonetheless.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/17/2003 2:06:53 PM
slammu123 Posted - 06/17/2003 : 12:58:14 PM
Hi
I tried this code but it says that "GetReal" is not defined or does not have a matching prototype.


Mike Buess Posted - 06/16/2003 : 5:15:27 PM
As you've probably guessed by now, a complex function will generate two output datasets. Actually, there could be four (real, imaginary, amplitude and phase). Since you haven't said which are meaningful to your analysis I'll show you how to get them all.

1> First you must set up your worksheet such that it has the input columns A, B, X and Y as well as the output columns Re, Im, Amp and Ph.
2> Double click on each of the output columns and set its format to 'numeric' instead of 'text+numeric'. (The following code crashed Origin until I did that.)
3> Use the following code in an Origin C function.

WorksheetPage wpg = Project.Pages();
string wksName = wpg.GetName(); // get wks name
Dataset dA(wksName + "_A"); // declare datasets
Dataset dB(wksName + "_B");
Dataset dx(wksName + "_X");
Dataset dy(wksName + "_Y");
Dataset dRe(wksName + "_Re");
Dataset dIm(wksName + "_Im");
Dataset dAmp(wksName + "_Amp");
Dataset dPh(wksName + "_Ph");
vector<complex> vf; // declare a complex output vector
vf = dx*dy*exp((dA+dB)*1i); // your function
vf.GetReal(dRe); // extract real data
vf.GetImaginary(dIm); // extract imaginary data
vf.GetAmplitude(dAmp); // extract amplitude data
vf.GetPhase(dPh); // extract phase data

4> Make sure that column A is set as X and the rest Y.
5> Select the output columns you want to plot and choose a plot type from the Plot menu.

Hope that helps.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/16/2003 5:15:59 PM
slammu123 Posted - 06/16/2003 : 1:15:53 PM
I want to plot the expression
F=x*y*exp(i*(a+b)) with respect to a .
here x,y,a,b, are datasets and exp(i*(a+b))refers to a complex number.
How do I do that?

Mike Buess Posted - 06/13/2003 : 6:27:17 PM
That will again require two output columns... one for the real part, 1+cos(a+b), and the other for the imaginary part, sin(a+b).

WorksheetPage wks = Project.Pages();
string wksName = wks.GetName(); // get name of active worksheet
Dataset dA(wksName + "_A"); // eg, data1_A
Dataset dB(wksName + "_B");
Dataset dG(wksName + "_G");
Dataset dH(wksName + "_H");
dG = 1 + cos(dA+dB);
dH = sin(dA+dB);

Mike Buess
Origin WebRing Member
slammu123 Posted - 06/13/2003 : 5:51:20 PM
I would like to add another column for example:
g=1+exp(i*(a+b))
where a and b are different columns in the worksheet and I want to put them in the column named g in the same wokrsheet.

Mike Buess Posted - 06/13/2003 : 3:41:49 PM
You want to multiply each row of a column by exp(ix)? Worksheet cells will not hold complex data so you'll have to create two columns (real and imaginary) for the results. Assuming you're operating on the first column of the active worksheet here's the easiest way to put the results in columns 2 and 3. It makes use of the relationship exp(ix) = cos(x) + isin(x) ...

void test(double x)
{
Worksheet wks = Project.ActiveLayer();
Dataset dd(wks,0); // first column. (Origin C uses zero based indexing.)
Dataset dRe(wks,1); // second column
Dataset dIm(wks,2); // third column
dRe = dd * cos(x);
dIm = dd * sin(x);
}

Mike Buess
Origin WebRing Member
slammu123 Posted - 06/13/2003 : 2:50:32 PM
what should i do if i want to calculate the phase factor for each of the values in a dataset and put the result in another column of the worksheet?
cpyang Posted - 06/13/2003 : 12:58:40 PM
Or you can multiply by 1i, like

 
void test(double x)
{
out_complex("exp(ix)=",exp(x*1i));
}




CP


Mike Buess Posted - 06/13/2003 : 11:15:09 AM
A complex argument must have a real and imaginary part.

void test(double x)
{
complex cc(0,x); // real=0, imag=x
out_complex("exp(ix)=",exp(cc));
}

test(3);
exp(ix)=-0.989992+0.141120i

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/13/2003 11:17:00 AM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000