Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Gauss-Jordan elimination method for inverse matrix

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-14-2019
06:46 PM

07-14-2019
06:46 PM

I try in Mathcad to build Gauss-Jordan method for obtaining the inverse matrix but it looks quite difficult.

It is closed to Jordan elimination method, but on the right side we consider initially (in the augmented matrix) an unit matrix. Did anyone build this method in Mathcad?

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

08-22-2019
02:19 PM

32 REPLIES 32

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-14-2019
07:33 PM

07-14-2019
07:33 PM

Re: Gauss-Jordan elimination method for inverse matrix

You may look up algorithms in "Numerical Recipes", I guess.

Writing an all purpose matrix-inverse-function and implementing it in Mathcad would require the knowledge of some "tricks" to make the algorithm as stable as possible, finding the appropriate pivot element, etc.

I am sure you can find a lot of references about this algorithm after a short internet research.

But what would be the benefit compared with Mathcads built-in algorithms, which usually are well tested, quite stable and much faster than anything implemented in Mathcads programming language?

You may be interested in this thread

https://community.ptc.com/t5/PTC-Mathcad/Gauss-Jordan-rref/td-p/273580

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-14-2019
07:40 PM

07-14-2019
07:40 PM

Re: Gauss-Jordan elimination method for inverse matrix

MAthcad fucntions are Black boxes. I want to apply just the numerical method Gauss-Jordan for the inverse of a matrix, a method that is open, transparent, and verifiable.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-14-2019
08:28 PM

07-14-2019
08:28 PM

Re: Gauss-Jordan elimination method for inverse matrix

@tubar wrote:

So for the start you sure would need some good advice about how to implement a stable algorithm.

Many algorithm implemented natively in Mathcad were based on the ones found in the above mentioned "Numerical Recipes" -> http://www.numerical.recipes

In Prime some were exchanged for the KNITRO tool box (with no advantage as far as I can tell).

Next step would be to implement the algorithm in C or the like and turn it into a user DLL which can be used from within Mathcad.

Then you may have functions which are fully verifyable and transparent which hopefully are as fast and reliable as Mathcad's built-in at the high price of a lot of work.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-14-2019
09:05 PM

07-14-2019
09:05 PM

Re: Gauss-Jordan elimination method for inverse matrix

OK, are interesting the desires of PTC about Mathcad, but I remain faithful to the classical numerical methods implemented as they by the user itself.

The representation of the Mathcad's logical algorithm is very closed to the General Flowchart ( the logical scheme) of the algorithm of solving the problem, that's why I like it to use this way instead of Built-in functions.

I have the C++ and Matlab codes for "Gauss-Jordan elimination method for inverse matrix" and I want also to obtain a representation of it in Mathcad:

// Gauss-Jordan elimination for finding the inverse matrix

#include <iostream>

#include <vector>

using namespace std;

// Function to Print matrix.

void PrintMatrix(float ar[][20], int n, int m)

{

for (int i = 0; i < n; i++) {

for (int j = 0; j < m; j++) {

cout << ar[i][j] << " ";

}

printf("\n");

}

return;

}

// Function to Print inverse matrix

void PrintInverse(float ar[][20], int n, int m)

{

for (int i = 0; i < n; i++) {

for (int j = n; j < m; j++) {

printf("%.3f ", ar[i][j]);

}

printf("\n");

}

return;

}

// Function to perform the inverse operation on the matrix.

void InverseOfMatrix(float matrix[][20], int order)

{

// Matrix Declaration.

float temp;

// PrintMatrix function to print the element

// of the matrix.

printf("=== Matrix ===\n");

PrintMatrix(matrix, order, order);

// Create the augmented matrix

// Add the identity matrix

// of order at the end of orignal matrix.

for (int i = 0; i < order; i++) {

for (int j = 0; j < 2 * order; j++) {

// Add '1' at the diagonal places of

// the matrix to create a identity matirx

if (j == (i + order))

matrix[i][j] = 1;

}

}

// Interchange the row of matrix,

// interchanging of row will start from the last row

for (int i = order - 1; i > 0; i--) {

if (matrix[i - 1][0] < matrix[i][0])

for (int j = 0; j < 2 * order; j++) {

// Swapping of the row, if above

// condition satisfied.

temp = matrix[i][j];

matrix[i][j] = matrix[i - 1][j];

matrix[i - 1][j] = temp;

}

}

// Print matrix after interchange operations.

printf("\n=== Augmented Matrix ===\n");

PrintMatrix(matrix, order, order * 2);

// Replace a row by sum of itself and a

// constant multiple of another row of the matrix

for (int i = 0; i < order; i++) {

for (int j = 0; j < 2 * order; j++) {

if (j != i) {

temp = matrix[j][i] / matrix[i][i];

for (int k = 0; k < 2 * order; k++) {

matrix[j][k] -= matrix[i][k] * temp;

}

}

}

}

// Multiply each row by a nonzero integer.

// Divide row element by the diagonal element

for (int i = 0; i < order; i++) {

temp = matrix[i][i];

for (int j = 0; j < 2 * order; j++) {

matrix[i][j] = matrix[i][j] / temp;

}

}

// print the resultant Inverse matrix.

printf("\n=== Inverse Matrix ===\n");

PrintInverse(matrix, order, 2 * order);

return;

}

// Driver code

int main()

{

int order;

// Order of the matrix

// The matrix must be a square a matrix

order = 3;

float matrix[20][20] = { { 5, 7, 9 },

{ 4, 3, 8 },

{ 7, 5, 6 },

{ 0 } };

// Get the inverse of matrix

InverseOfMatrix(matrix, order);

return 0;

}

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-15-2019
06:13 AM

07-15-2019
06:13 AM

Re: Gauss-Jordan elimination method for inverse matrix

If you use real Mathcad (not Prime but Mathcad 15) then you find information on how to write Mathcad DLLs if you go to "Help" and chose "Developer's Reference" .

Since I have little interest in Prime I am not sure where you could find the appropriate information for this version.

As far as I recall there are some threads in this forum dealing with DLLs for Prime.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-15-2019
06:16 AM

07-15-2019
06:16 AM

Re: Gauss-Jordan elimination method for inverse matrix

I dont care DLLs. I just want to build a Mathcad algorithm for Gauss-Jordan elimination method to obtain the inverse matrix.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-15-2019
06:32 AM

07-15-2019
06:32 AM

Re: Gauss-Jordan elimination method for inverse matrix

@tubar wrote:

Oh, I see. So you don't trust Mathcad's built-in algorithms but you trust Mathcad's built-in programming language, which is a black box, too ;-)

Implementing such a basic algorithm in a slow, interpreted language, as the Mathcad programming language at worksheet level is, is IMHO maybe a good exercise for students to do but nothing you would use for real, I guess.

Anyway - just go ahead and give it a try. If you get stuck you may come back and post your worksheet here to get help.

Maybe the link to the forum thread I posted above can be helpful (even though the matrix is only brought to echelon form there.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-15-2019
06:59 AM

07-15-2019
06:59 AM

Re: Gauss-Jordan elimination method for inverse matrix

I want to build the Algorithm in the Mathcad interface. Already, in this Forum are presented some Jordan elimination algorithms (applied to obtain the solution) but this time I want to find the inverse matrix.

Unlike the other methods, the Gauss-Jordan elimination bring you to the exact/analytic solution (as you can see in the attached image file from the first message).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-15-2019
07:13 AM

07-15-2019
07:13 AM

Re: Gauss-Jordan elimination method for inverse matrix

@tubar wrote:

I want to build the Algorithm in the Mathcad interface. Already, in this Forum are presented some Jordan elimination algorithms (applied to obtain the solution) but this time I want to find the inverse matrix.

Unlike the other methods, the Gauss-Jordan elimination bring you to the exact/analytic solution (as you can see in the attached image file from the first message).

Not sure what you mean by "exact/analytic".

Does Mathcads symbolics not qualify for "exact" and "analytic" in your eyes?

And the C-program you posted is only providing a numeric solution, not a symbolic, "exact" one. So whats the benefit?

But of course you are free to give it a try and come back for help with programming in Mathcad, if needed.

Top Tags