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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to find square root of a matrix

MySchizoBuddy
1-Newbie

How to find square root of a matrix

How do you find the square of an each individual element of a matrix.

34 REPLIES 34

Mike,
Look at my response to Richard, in the attached file, I made some changes for comparisons.

To have a fair test, with larger matrices, in the case 10x10 is large, you must preallocate the martices as shown in the artical previousley referenced.

And, If you had to do more steps, say as series of equations, the vecorizing each step verses one program to do each step, I suspect the results will not even be in the same ball park.

Any way, I have just provided some examples, please have a look at.

PS.

It looks like if you are writing a routine that is to be used over and over, you may want to test a couple of methods and select the best for that situation.

MikeArmstrong
5-Regular Member
(To:wayne)

Look at my response to Richard, in the attached file, I made some changes for comparisons.

To have a fair test, with larger matrices, in the case 10x10 is large, you must preallocate the martices as shown in the artical previousley referenced.

Wayne,

Your worksheets has a vast amount of data and basically hung my laptop up. My simple example was to shoe that preallocating a vector can speed things up.

To be honest I don't trust these time functions. Look at the image below.

All I have done is change the location of the last element and the time changed.....

11.jpg

Mike

Mike,

I know, they are sort of relative, depends on what else is running on your computer. Also can depend on order because available resources can effect the solution. I also changed order, and did a 100x100 matirx, But the trend and relative magnitudes are comparable:

Vectorize is less efficient as the matrix increases in size.

Richard seems right (supprise), Mathcad likes to do computations with columns (vectors) of a matrix rather than element by element,
but in the long run, it might depend more on the specific problem. It appears that element by element, works pretty well, and when done this way, dose not seem to matter much if column wise or row wise.

For large problems, I think its generally true the more you do inside a program the better, and using subroutines (that dates me) possibly works well because I think the memory is freed up after the subroutine returns back to the calling program, as it would be in a C program. (perhaps Richard can comment on this also).

MikeArmstrong
5-Regular Member
(To:wayne)

I suppose it is a case of suck it and see.

As you said it depends on the computer, programs running, size of matrix....etc etc.

Mike

MikeArmstrong
5-Regular Member
(To:RichardJ)

In the Help, something like "features in depth", they talk about using the vectorize operation and it being slow/

I actually thought that would be the case.

Mike

Top Tags