×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Vectors with Complex Numbers in Mathcad

## Vectors with Complex Numbers in Mathcad

(OP)
Hi,
Longtime user of Mathcad (I started at version 5). I've only recently become concerned with complex numbers. Budding interest in electrical engineering, doing Fourier analysis, etc.
Since the Fourier analysis function FFT() delivers a vector containing complex numbers, it would be nice to simply find the maximum absolute valued element of the result, its rank, and then carry on. This isn't working out for me.

To make a simple example, rather than dumping a thousand lines on the screen, I'll provide an example with just 4 complex numbers and demonstrate my problem. I've been using these as a "sanity" check for myself as well as a way to try finding solutions. Still stuck. Take 4 complex numbers like these:

0.31+0.70i
0.21-0.89i
0.36+0.02i
0.44-0.14i

These four have been entered into a Mathcad vector, named "x", and the first number is in rank "0" of the vector (Mathcad numbers its ranks starting from zero by default).
I want to find the MAXIMUM absolute valued number in the vector. Let's do this manually to see where we're going:

|0.31+0.70i| = 0.766
|0.21-0.89i| = 0.914
|0.36+0.02i| = 0.361
|0.44-0.14i| = 0.462

Now that I have done all the work, it's obvious that 0.914 is the maximum absolute value, and it comes from (0.21-0.89i) in rank 1. Now I want to be able to find this with a function, not manually. I will be doing FFT's on 1000's of samples at a time. There should be a function that can find this for me. Wouldn't it be nice if max() would do this. But no.

The function max() sifts through the complex numbers, picks whatever largest real number it can find, then whichever imaginary component it can find, and slaps them together! The User's Guide explicitly says the max(A) function finds the "Largest element in arry A. If A has complex elements, it returns the largest real part plus i times the largest imaginary part". Why would I want it to do this? It corrupts the complex number. Worse, the max() function is used in the Guide's examples for FFT functions! How many users get stumped by this? How many get the garbage from max() and don't realize it?

The result in Mathcad: max(x) = 0.44+0.70i ---this is garbage. It is not one of the four numbers in the vector.

I have tried combining the max() function with || absolute value operators but this spews out more garbage.
For instance:

|max(x)| = 0.827 --- which is just the absolute value of 0.44+0.7i if you were to work it out. more garbage.

max(|x|) = 1.329 --- no idea where that result comes from.

It may be blatantly obvious but I would gladly appreciate any suggestions.

STF

### RE: Vectors with Complex Numbers in Mathcad

What you need is max(|x|)= but you have to vectorize that expression, otherwise you get the magnitude of the vector x itself. Vectorization is a powerful operator which very often can be used to great advantage.
BTW, its always better to attach a worksheet rather than describing what you have typed. It makes it also easier for people to reply with a fixed sheet and also gives a hint as to the version the question is aimed for.

### RE: Vectors with Complex Numbers in Mathcad

(OP)
Hi rmix22,

x already is a vector. When I vectorize it, the numbers are changed into real numbers. The UG tells me that vectorizing a vector returns a vector of the sine of each value.

The worksheet has become messy, with all my little experiments, so it's very hard to read, and only 2% of it has the complex number problem.
But if it really helps, I can chop it down for you.

STF

### RE: Vectors with Complex Numbers in Mathcad

(OP)
More playing around with "vectorizing".

The order in which it occurs matters. I was vectorizing the vector, then taking the absolute value. No, I had to use the absolute value operator, then vectorize the result of that, then find the max() of that.
I can't just type this in ASCII on the screen, but the point is that I have to get the operators in the right order for it to work.

I think I got it, thanks!

STF

### RE: Vectors with Complex Numbers in Mathcad

Vectorizing has nothing to do with the sine function - maybe it was an example in the help using sine.

If you vectorize an expression and the expression contains a vector (or more of equal dimension; no matter if real or complex), the expression is evaluated for each vector element one by one and the results are collected in a new vector. If an operation (like squaring, divison, sin(vector)) which is not defined for vectors is used, Mathcad automatically applies an implicit vectorization. But magnitude (|x|) or multiplication are defined for vectors and so these are used if not otherwise stated by using explicit vectorization.

#### Quote (SparWeb)

I can't just type this in ASCII on the screen,
Thats exactly why I suggested to attach a worksheet. A small sample sheet like the attached to this post would have sufficed. We wouldn't have needed the huge original sheet.

### RE: Vectors with Complex Numbers in Mathcad

(OP)

#### Quote:

If you vectorize an expression and the expression contains a vector (or more of equal dimension; no matter if real or complex), the expression is evaluated for each vector element one by one and the results are collected in a new vector. If an operation (like squaring, divison, sin(vector)) which is not defined for vectors is used, Mathcad automatically applies an implicit vectorization. But magnitude (|x|) or multiplication are defined for vectors and so these are used if not otherwise stated by using explicit vectorization.

Yup, that's exactly it. Thanks for pointing this out because that was what I was missing.

PS, I'm currently using MC13 version 13.1. I lost the User's Guide from 13 but I still have the Guide from version 7. In terms of the math that I use it for, I see no difference between MC 13 and MC7, or MC5 for that matter. Upgrades have been driven solely by operating system compatibility, and avoidance of unstable versions (such as MC6).

Further to my FFT experiments, I discovered that the complex "CFFT()" rather than the discrete FFT(), is more likely to give the right max() value if calculated without the vectorize operator (as demonstrated in the UG example). That's because the array that the CFFT function spits out is twice as long as the array given by the FFT. The additional values in the array are the same as the first ones, but the sign of the imaginary component is reversed. So if the value in the array at j=50 is 0.277-0.38i, then you can go to N-j and find 0.277+0.38i, which greatly increases the odds that max() will find the right answer.

As for the sin() question, what I'm reading in the UG is confusing, but irrelevant to what I'm trying to do. Some finger trouble on my end didn't help. The book really does say "if v is a vector, sin(v) is an illegal expression" Very strange, but never mind. I'm not going to worry about it because obviously it works just fine when I try to do it now.

STF

### RE: Vectors with Complex Numbers in Mathcad

Actually sin(v) would not be a valid expression unless vectorization is applied. I'm not sure when implicit vectorization was introduced - maybe after version 7.
You could search the net for a pdf of the user guide for version 11. This was the last one which was complete including a complete reference. Beginning with version 12 (the worst version ever, apart from Prime, of course) the user guide was significantly truncated (and with Prime there is no UG whatsoever).

Not sure what you are working on but it could be that you find that thread in the main Mathcad forum of interest: http://communities.ptc.com/message/212019#212019

Find attached the sheet from my last post in MC13 format.

### RE: Vectors with Complex Numbers in Mathcad

(OP)
"implicit vectorization" Yes that would be why the UG says one thing and I can do the other. So now I actually am doing math where one version is different from another.

I haven't been paying attention to the Mathsoft -> PTC business. I did download PTC prime but I don't like to use it.
I will pursue the links and the attachment you provided later (dinnertime in my time zone) but thanks again for the very quick responses.

STF

### RE: Vectors with Complex Numbers in Mathcad

#### Quote (SparWeb)

I did download PTC prime but I don't like to use it.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!