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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

workaround for mathcad 15 plotting bug

prop_design
15-Moonstone

workaround for mathcad 15 plotting bug

hi,

 

i seem to have run into a bug with mathcad 15 plotting. i'm sure there is a way around it. however, i don't know how to do it. i put the question in the file. it's near the bottom of the file. i think there needs to be an if statement that checks to see if both elements of the matrix are negative. if so, make them positive. the matrix with the problem is called 'mode1'.

 

sorry, the file is kind of a mess right now. i want to clean it up and post it as an update to a very old thread on here. i was able to take something someone posted 'pre mathcad 15' and get it working with mathcad 15. however, i wanted to get this plotting glitch fixed before i did that.

 

i also found that a number of the eigenvalue and eigenvector functions have bugs as well. luckily, the ones i used in this file seem to work good.

 

thanks,

 

anthony

1 ACCEPTED SOLUTION

Accepted Solutions

On contrary to the Eigenvalues, Eigenvectors are not unique. Every multiple of an Eigenvector is again an Eigenvector corresponding to the same Eigenvalue. This said you can always multiply each Eigenvector with the sign of its first component. This will always make the first component positive.

Werner_E_1-1667010933034.png

 

The order of the Eigenvectors given by "eigenvecs" may not correspond to the order of Eigenvalues returned by "eigenvals" (actually I am not sure about that). To be on  the save side you can use "eigenvec" (without the trailing "s") to give you an Eigenvector for a specific Eigenvalue.

Werner_E_0-1667010672307.png

I am not sure why the signs of the components of the first Eigenvector is different from the one given by "eigenvals", but of course both are correct and valid.

 

According the vector field plot you are using: I am not sure what you think its showing?? You may look up the explanation of the vector field plot in the help to see what kind of data structures it expects as its input.

Your vector is interpreted a a vector of complex numbers, where the real part represents the horizontal and the imaginary part represents the vertical direction of the arrow. The starting points of the arrows are always the row and column numbers.

For some reason (I guess its a bug) this does not work if both numbers are negative. Strange enough it helps to simply add an "imaginary null vector".

Werner_E_2-1667012561468.png

If your goal was to plot the two Eigenvectors, both starting at (0;0), you could do it that way:

Werner_E_3-1667012860486.png

 

EDIT: Could be a bit easier achieved by one of the following ways

Werner_E_0-1667013643596.png

 

 

View solution in original post

17 REPLIES 17

On contrary to the Eigenvalues, Eigenvectors are not unique. Every multiple of an Eigenvector is again an Eigenvector corresponding to the same Eigenvalue. This said you can always multiply each Eigenvector with the sign of its first component. This will always make the first component positive.

Werner_E_1-1667010933034.png

 

The order of the Eigenvectors given by "eigenvecs" may not correspond to the order of Eigenvalues returned by "eigenvals" (actually I am not sure about that). To be on  the save side you can use "eigenvec" (without the trailing "s") to give you an Eigenvector for a specific Eigenvalue.

Werner_E_0-1667010672307.png

I am not sure why the signs of the components of the first Eigenvector is different from the one given by "eigenvals", but of course both are correct and valid.

 

According the vector field plot you are using: I am not sure what you think its showing?? You may look up the explanation of the vector field plot in the help to see what kind of data structures it expects as its input.

Your vector is interpreted a a vector of complex numbers, where the real part represents the horizontal and the imaginary part represents the vertical direction of the arrow. The starting points of the arrows are always the row and column numbers.

For some reason (I guess its a bug) this does not work if both numbers are negative. Strange enough it helps to simply add an "imaginary null vector".

Werner_E_2-1667012561468.png

If your goal was to plot the two Eigenvectors, both starting at (0;0), you could do it that way:

Werner_E_3-1667012860486.png

 

EDIT: Could be a bit easier achieved by one of the following ways

Werner_E_0-1667013643596.png

 

 

prop_design
15-Moonstone
(To:Werner_E)

hi werner,

 

unfortunately eigenvec and the other function i think it's genval genvec. they all randomly fail depending upon inputs. the only function that worked for all the test cases i ran was eigenvecs eigenvals. there just seems to be some sort of plotting bug if both entries are negative. the plots duplicate something i'm testing in fea software. so i know what they are showing. i already got the sorting worked out based on a decades old post. i just tweaked a few things to get it working with v15. i'll try to apply what you are saying about flipping the signs. i'm still confused on how to do that. it will plot if both are positive or one is positive and one is negative. it won't plot if both are negative. it would be fine to always make it positive. the only problem is i can't just do an absolute value because sometimes one is supposed to be negative. so that is where i was thinking an if statement would be needed.

I edited my first reply in the meantime and attached a screenshot showing what I meant by multiplying by the sign of the first vector component.

I also added a workaround which makes your plot work in case of two negative numbers (adding the imaginary null vector).

You may ignore my last remarks about plotting the vectors if what your plots show is already exactly what you are looking for.

 

Can you post an example where "eigenval" returns a wrong result whereas "eigenvals" doesn't?

prop_design
15-Moonstone
(To:Werner_E)

hi werner,

 

the trick with adding zero imaginary values should work. thanks a lot. i attached an updated file, with that fix. for anyone else reading this, make sure to type 1i or 1j to get the imaginary number to work. i was stumped for awhile with that. typing just i or j does not work. it says as much in the help.

 

wrt to sending files of the other functions failing. that's kind of hard to do because i have so many files and test cases. eigenvecs and eigenvals always worked though. so i will stick with those. all of the other functions in that category failed at one point or another. usually when one value was very small. however, i needed that to match various fea models. so if you have a 2x2 matrix and use any of the eigen functions. just set one of the values to something like 1e-8 or 1e-16 and it should fail or give an incorrect result. i'm comparing to fea so i know the values i'm looking for. also the eigenvecs and eigenvals functions match the fea. so that lets me know when the other functions have issues.

 

once i get this file cleaned up, i will post it to a different thread. since i learned a lot from that old post. it just needed a few small tweaks, since it was a pre v15 post.

If you come across a specific matrix where the results of "eigenvectors" and "eigenvector" differ, I would be interested.

I tried a few matrices with small values but never came across any significant difference (apart from expected rounding errors).

Here's an example

Werner_E_0-1667048586568.png

 

We can also compare the results of symbolic evaluation which give us a different, but equivalent set of eigenvectors

Werner_E_1-1667048636879.png

 

prop_design
15-Moonstone
(To:Werner_E)

hi werner,

 

i added some comparisons at the end of the file. there are four examples in the file. you have to rearrange them to see a given example. some compare ok some don't and quite a few fail to generate a result. that's why i went with eigenvals and eigenvecs. they were consistent and compared to fea. all the rest had various issues.

 

i don't know what's going wrong with eigenvec. that's the worst offender. maybe i'm doing something wrong there.

 

Update; I think I messed something up. I attached a corrected version. However, the problems I were mentioning are still there.

It looks like the pink example is the best one to use, to show the problems. That shows errors with genvals, genvecs, and eigenvec

I see!

The matrix

Werner_E_0-1667064513247.png

seems to push Mathcad to the limits of its numerical capabilities.

Its interesting to see that "eigenvecs" still returns results, while "eigenvec" fails.

Werner_E_2-1667064864786.png

 

 

prop_design
15-Moonstone
(To:Werner_E)

hi werner,

 

i'm glad you can see the errors now. even for normal inputs (the blue and green examples), eigenvec fails. is there something i'm doing wrong there, or are you getting the same problems? it says it's failed to converge.

I experience the same error message. I guess the reason is the high values and that they are very similar. Even though because of the large numbers the determinant of the matrix is around 10^26, the elements in the matrix are very similar, close. So I can imagine that an algorithm may fail here as the determinant can be said to be close to zero in relation to the maginitude of its elements. I am not surprised that "eigenvec" fails but I am surprised that while it fails "eigenvecs" does not. I wonder about the different algorithms used behind the scenes.

prop_design
15-Moonstone
(To:Werner_E)

thanks werner,

 

here is the same file with the blue example shown. eigenvec still fails. that's what makes me wonder if i'm doing something wrong still. i added a few more outputs in the comparison section.

In the meantime I played around a bit and wrote with the help of Mathcads symbolics my own "EigenVals" and "EigenVecs" functions. For non-singular 2x2 matrices only 😉 They seem to work OK. Maybe they can be of help.

Just look at the end of your file.

Here you are indeed doing something wrong. Your vector "freq" does not contain the Eigenvalues but the root of them, because you defined it that way:

Werner_E_0-1667071744719.png

The second argument of "eigenvec" must be an Eigenvalue, so you would have to provide the square of "freq".

Werner_E_1-1667071799840.png

As you can see its not necessary to get rid of the units.

Werner_E_0-1667071934903.png

 

prop_design
15-Moonstone
(To:Werner_E)

thanks werner,

 

great catch. yeah for me eigenvalues are in Hz (rev/s). i've never seen them the way mathcad is doing it. so that gets the green and blue examples working. only the other two fail. but it's fine. as long as one way works, that's good enough for me. thanks for your help.

Mathcad sees the Eigenvalues from a mathematical point of view. The Eigenvalues of a Matrix M are the solutions k of the Equation |M - k*E|=0 where E is the identity matrix. So obviously the Eigenvalues k must have the same dimension (units) as the elements in the matrix M, otherwise the units would not balance.

In my answer above where I created my own "EigenVals" function you can see how the Eigenvalues can be calculated based on the matrix elements. Hereby the correct unit automatically results quite by itself.

prop_design
15-Moonstone
(To:Werner_E)

your work is impressive as always. i would never have been able to do what you did. thanks for sharing that.


@prop_design wrote:

your work is impressive as always. i would never have been able to do what you did. thanks for sharing that.


Use it with care. Its a quick hack and not really tested as much as needed. But it looks like its quite stable.

Top Tags