cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

5-Regular Member

## Defining complex numbers

Hi everybody!

Primary question is:

How could one define a complex number?

I tried it  assigning

Re(C):= Formular1

Im(C):= Formular2

After that I assigned:  G:=Re(C) + Im(C)

This shouldn't be neccessary, because a complex number is defined by its components. But it is obviously neccessary. Without that a plot doesn't work.

I attach the whole working sheet and the Input data of the load in the time Domain.

Udo

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:UdoPeil)

Udo,

The value 1i (typed just like that, first a '1' then an 'i', nothing more, nothing less !) is a predefined value, unit if you will, in Mathcad and represents what every mathematician understands as the unit of an imaginary number.

So, as Werner and myself wrote, if you type c:4+5i, you define c as a complex number with real part 4 and imaginary part 5.

However appending i to a variable name does NOT make that variable imaginary. To do that you have to multiply it with the imaginary unit, which is...... 1i.

In your example you would/should: c:=reS +ImS*1i.

Re() and Im() are predefined functions in mathcad, congruent with ordinary mathematical understanding, that take the real and imaginary part respectively of their argument. With c defined as the first example above: Re(c)=4 and Im(c)=5.

You should NOT redefine Re and Im.

Be patient, come here as often as you need.... and you will learn.

Success! and Frohe Ostern.
Luc

27 REPLIES 27
24-Ruby V
(To:UdoPeil)

To attach a Mathcad worksheet you have to put it in an archive (zip, rar, 7z,...) first because of a sever bug in the forum software used here.

To define a complex number with its components you simply type z:=2+3i or z:=2+3j. Its important that you don't type a space or a multiplication sign between the 3 and the i. If you want to use the imaginary unit alone you have to type 1i. In real Mathcad after leaving the math region the "1" is not displayed anymore, in mean Prime this unfortunately is not the case.

You should state which version of Mathcad you are using and what exactly you are trying to achieve.

Im(C) will give you the imaginary part of a complex number and by the definition this is a simple real number (it does NOT include the imaginary unit i).

5-Regular Member
(To:Werner_E)

Thank you Werner,

this is clear. My problem is somewhat different.

Thus I attach the worksheet as a zipped file. The needed data file will not taken into the list of attached files. it seems that only one file could be attached. Anyway, the datafile is attached at my first mail at the PTC mail-Center.

The problem occurs at the very end. All is explained or discussed there.

Discussion is written in German, I don't know, if you'll understand that. It is not impossible, because your first name is German origin...

If not, please respond shortly and I will translate it to English.

Thanks in advance and happy eastern!!

Udo

23-Emerald I
(To:UdoPeil)

I have your version 15 file, and your data.  (You can embed the data into a version 15 file via a data table.)

Unfortunately my German is no better than any standard Us Citizen--almost worthless.  I attempted to work down thru your sheet and failed.  If you could translate, then maybe I can help!

Sorry!

24-Ruby V
(To:UdoPeil)

See, if the attached file helps

BTW, this forum software has a lot of drawbacks and really sucks.
I think you are able to attachj more than one file, but you must highlight them all at thesame time and then insert them. After you inserted a file, there seems to be no option to attach another one - ridiculous.

EDIT: Seems this is wrong - we are indeed offered this option now (was not the case in the first months when the forum software changed) At least now when I am editing this post I see the "Durchsuchen" button which would do the job.

And you can always resort to putting all files in one zip-archive and then post this single file.

5-Regular Member
(To:UdoPeil)

Thanks again Werner!

The problem is solved so far. My problem was, how to define a complex number from variables. You can't attach just an i to name of the var, because the name plus the added i is the new name of the var. Multiplying var*i is not allowed.

Somebody here here gave the solution hint: Multiply the var with 1i! Very simple, that I aske, why I don't got myself this solution...

But anyway it worked .

Unfortunately not complete. I have a new problem calculation the IFFT. Please see the attachment at the very end.

Question and comments are given in the worksheet (end).

Udo

23-Emerald III
(To:UdoPeil)

Look up the information on the IFFT function. It requires 1+2^(m-1) elements, so rather 257 elements in your case.

Success!
Luc

And while you're at it. Look up the information on fft(), cfft(), FFT() and CFFT() functions and their inverses. There is a difference in scaling factor and in the number of samples they accept.

5-Regular Member
(To:LucMeekes)

Hi Luc,

I am surprised about the 1+--

I Copy from the Users Guide:

in my case n=9, i.e. size of the frequent< vector is 2^9=512. I have it from 0 - 511. This is the lengths of the time domain function.

I really started at the first page with n=8 and made the time vector twice.

The frequency transform has a length of half the time domain function, or 2^n-1 i.e. 256.

Bot Loops, I now see the 1 in front of it. This is against all theories of FastFourierTransformation. Why one more? And how to get it.

Normally you preset the number of n and make your FFT. The inverse IFFT works automatically, as it is shown above at the right adjacent page.

23-Emerald III
(To:UdoPeil)

Udo,

As you can read in the Mathcad documentation of the fft() functions, the frequency of the k-th element is k *fs/n, where fs is the sampling frequency and n is the number of data samples in the input vector.

This means that for k=0, the frequency is 0 Hz. It represents the DC or offset value of your signal.

In my example, the mean of H:

Success!
Luc

5-Regular Member
(To:LucMeekes)

Ok, Luc,

First I have do dive in your example and then in the background of the Mathcad  procedure. I'll come back later on!

And again: Thank you very very much!

Best regards and happy easter

Udo

23-Emerald III
(To:UdoPeil)

Apparently you didn't read all literature about it (and that's understandable, because there's a lot). I'd recommend this:http://www.dspguide.com

From that book I took:

Notice how the (time domain) signal contains 128 samples, 0 through 127, while the DFT contains 65 points, 0 through 64. Also notice that the offset value (DFT at index 0) is pure real (it has no imaginary part) because there is no phase in offset.

Success!
Luc

5-Regular Member
(To:LucMeekes)

Hi Luc,

that was the point. Now it works!1 Thank you very much.

But noe I do have another problem, which I don't know how to tackle.

I attach a screen shot for explanation. I construct again a complex vector from a real and imaginary part with multiplication of *1i That doesn't work this time, the imaginary. part imG is red and the error message is "Must be a scalar or a matrix".

But it is a matrix, please look at the right page. I really hanging through with that.

Best regards

Udo

23-Emerald III
(To:UdoPeil)

Gutenabend Udo,

Your data (both reG and imG) are all text strings (notice the quotes).

Try using the str2num() function to interpret them as numbers.

As an alternative, try using the READPRN() function to read in the data, that might give you a numeric matrix straight away.

Success!
Luc

23-Emerald I
(To:UdoPeil)

Werner has given you the primer on creating and using imaginary numbers.

Attached is one simple example using your data file. (Prime 3.0)

5-Regular Member
(To:Fred_Kohlhepp)

Hi Fred,

thanks for your reply, but my problem is a different one. Please have a look at the very end of the attached worksheet there all is explained and discussed. All explanations are written in German, if you don't understand, please come back shortly, I will then translate the discussion.

If you like to run the worksheet, you need the data file. Obviously one can't attach two files thus I beg you to load the data file from my former email to PTC mail-center..

Thanks in advance an a happy eastern

Udo

23-Emerald III
(To:UdoPeil)

First off, as Werner explained:

Then, at the very end of the file, you are confronted with nested arrays. the construct [256,1] tells you that the element is a vector, a matrix of (in this case) 256 elements high, one element wide.

To see the individual elements, you can instruct mathcad to 'expand nested arrays' on the 'result formatting' pop-up window. In this case I would advise against, since the display of this array will be big. Here's an example with smaller vectors:

You can attach more than one file to a post in this forum. But the second (and further) file(s) can only be attached by editing the existing post. That's what I did.

Success!
Luc

5-Regular Member
(To:LucMeekes)

Hi Luc,

thank you! I am a little step further and have a rough direction where I could investigate.

I know that a complex number is defined e.g. by c:=7+9i.

But this principle doesn't work if you operate with names. e.g. c:=reS +ImSi,

because the last name is interpreted to be a variable named ImSi and not ImS*i

If you do the last then i must be defined before e.g. as variable i:=1..something.

That is my problem, I think.

I tried the solution Re(c):=function. But this didn't work...

I.e.: No success (because I don't understand the whole sh...

Have a nice evening, Luc.

I have to leave now, and will be back over easter.

Thanks and best regards

Udo

5-Regular Member
(To:UdoPeil)

Please have a look at this attachment...

I will be back the latest on easter, I have to leave now.

Bye and thanks again!!

Udo

5-Regular Member
(To:UdoPeil)

Please have a look at this attachment...

I will be back the latest on easter, I have to leave now.

Bye and thanks again!!

Udo

23-Emerald I
(To:UdoPeil)

I think you're not realizing that Mathcad handles complex numbers as easily as it does integers.

Two files are attached:

• errors started down thru your sheet, and got terminated when you wrote "Re(G) :=  ReG."  This had the effect of redefining a built in function, Re(), to return a constant set of values.  So Re(G) returns an array, Re(2) returns exactly the same array, and ReG returns the same array.  Without destroying that illustration, I could not proceed.  (Once you reach the pink highlighted areas on the right-hand page you can stop, I just saved that file then renamed it to modify further.
• fixess (sorry for the spelling) continues onto (I hope) complete your task.  You generate a response function(?) G, then multiply it by the input.  You typed "G x F = S", then you went thru the same incorrect constructions "Re(S) := ReS," that you had before.  What you really wanted to do (I think) was to simply type "S := G LaF, where the array multiplication needs to be "vectorized", to get the FFT of the output.  It was then a simple matter to take the inverse FFT of S to get a time history trace.

I hope this is what you were trying to do, and I hope it illustrates your misconceptions about imaginary numbers in Mathcad.

And I hope you enjoyed your Easter!

23-Emerald III
(To:UdoPeil)

Udo,

The value 1i (typed just like that, first a '1' then an 'i', nothing more, nothing less !) is a predefined value, unit if you will, in Mathcad and represents what every mathematician understands as the unit of an imaginary number.

So, as Werner and myself wrote, if you type c:4+5i, you define c as a complex number with real part 4 and imaginary part 5.

However appending i to a variable name does NOT make that variable imaginary. To do that you have to multiply it with the imaginary unit, which is...... 1i.

In your example you would/should: c:=reS +ImS*1i.

Re() and Im() are predefined functions in mathcad, congruent with ordinary mathematical understanding, that take the real and imaginary part respectively of their argument. With c defined as the first example above: Re(c)=4 and Im(c)=5.

You should NOT redefine Re and Im.

Be patient, come here as often as you need.... and you will learn.

Success! and Frohe Ostern.
Luc

5-Regular Member
(To:LucMeekes)

Thats it, Luc!

Great!!

Multiplication with 1i and not just i. As most problems the solution is simple!!

Thank you again for helping me very engaged!

And again: Happy Easter!!!

Udo

23-Emerald III
(To:UdoPeil)

Success!

Luc

5-Regular Member
(To:LucMeekes)

My problem is somewhat different, Luc.

Please have a look at the attached worksheet. At the very end you'll find the problem and a discussion or comments. This is written in German. If you have problems to follow it, please give a short notice, I'll then translate it into English!

If you intend to run the worksheet you need in addition a data file. This is attached to my first mail. As far as I experienced it is possible only to attach just one file.

Thanks in advance and a happy easter

Udo

5-Regular Member
(To:LucMeekes)

My problem is somewhat different, Luc.

Please have a look at the attached worksheet. At the very end you'll find the problem and a discussion or comments. This is written in German. If you have problems to follow it, please give a short notice, I'll then translate it into English!

If you intend to run the worksheet you need in addition a data file. This is attached to my first mail. As far as I experienced it is possible only to attach just one file.

Thanks in advance and a happy easter

Udo

23-Emerald III
(To:UdoPeil)

Your post above proves that you can attach more than one file to a post...

If you have two vectors, one with the real part Vr and the other with the imaginary part Vi of an array of complex numbers, you can construct the array of complex numbers Vc by adding:

Vc:Vr+Vi*1i

Note: 1i, not 1*i.

Luc

23-Emerald III
(To:UdoPeil)

Anyway, this is what I get out of your data file, assuming the second column contains sampled data values:

Success!

Luc

24-Ruby V
(To:UdoPeil)

Hi Udo!

Looks like you did not look at the file I posted here some 3 hours ago as an answer to your questions, right?

In that file you will find some remarks and also I have the data embedded for convenience so we don't have to take care of the external data file.

Announcements
Top Tags