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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

4-Participant

## Prime 7, programing "if" any of these values.

Greetings, im trying to program something that fills a matrix automatically, but you can choose wich rows and columns to make 0 instead.

So far i can do it by hand, just setting what row and colum i want (fil=row), and adding extra conditions to the "if"

I tried to use a matrix instead, like row:=[1 2 3], so if i= any of those 3 values, it assign it 0, but it doesnt seem to work with a matrix, i wrote it something like "if i=fil1_i" (_i meaning subscript), but it doesnt compare it to the value on the matrix.

Im working with Power Flow equations, in this part i need to do a 2x2 matrix each space being a Jacobian matrix. Im trying to automate it, because this is with 2 "bars" so matrix are 2x2, but when its something like 6 bars i dont want to do everything by hand

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(To:DS_10135119)

I am not absolutely sure what you are trying to achieve, but maybe this function could be of help:

Prime 6 sheet attached

13 REPLIES 13
24-Ruby II
(To:DS_10135119)

24-Ruby V
(To:DS_10135119)

I am not absolutely sure what you are trying to achieve, but maybe this function could be of help:

Prime 6 sheet attached

24-Ruby II
(To:Werner_E)

There is no attachment in your message.

24-Ruby V

There is no attachment in your message.

Ooops, tnx! I just fixed it.

24-Ruby II
(To:Werner_E)

Bitte 😉.

24-Ruby V
(To:Werner_E)

Here is a slight variation

4-Participant
(To:Werner_E)

Thanks, that match function is just what i was looking for. Plus i did something so i can put four 2x2 matrix on a single big matrix (since the jacobian matrix is like that) to adjust the subindex so it starts at 0 when you reach each cuadrant (note that i changed matrix origin to 1, hence those i-1).

Now since you finally have to work with the actual values of that matrix, im looking into, either dont fill those rows/columns from the matrix so it ends up as a 3x3 in this case. Or take the info from this matrix and remove the required rows and columns, so i dont need to make a new matrix and manually put each element looking at the original matrix.

4-Participant
(To:DS_10135119)

So i applied that same program to calculate the actual values, and like i asked before, how could make a new 3x3 matrix with the non 0 values, so i dont have to do it by hand?, either by adding more commands to the program that gives me this result, or to trim the result matrix

24-Ruby V
(To:DS_10135119)

There might be better and more elegant ways, but here is a quick first attempt for a function which trims all rows and columns which consist of all zeros:

Prime 6 worksheet attached

24-Ruby V
(To:Werner_E)

Here is a version without the "IsElement" function

4-Participant
(To:Werner_E)

Thanks a lot. I was trying to understand your method, the just do columns but transpose and transpose back is a great idea.

I have a question since i been using mathcad for this semester only, why is it needed to declare the origin when you start a program? i see many people does it, but i notice i can get away with not doing it at all.

Also i didnt knew you could use the input matrix, do some work and output to a different matrix, that way you can fill another matrix with just the info you want. Thats another thing i was trying to figure out.

Very grateful for your help. Plus my teacher was impressed that i took the time to learn to program in mathcad since it wasnt necessary.

23-Emerald III
(To:DS_10135119)

You don't HAVE to set the value of ORIGIN. By default it is set to 0. Through the menu you can set it either 0 or 1, but if you define it on the sheet you can set other values as well.

People may tend to define it on (top of) the sheet to make clear which ORIGIN they use.

Success!
Luc

24-Ruby V
(To:DS_10135119)

The double transposition was done out of laziness as I did not want to write a trimZeroRows function, too. But if you are using really huge matrices, this could be a performance drawback. But by huge I am talking of matrices with much more than a few hundreds elements.

According ORIGIN:

The default value for ORIGIN is 0, but I noticed/assumed from your screenshots that you changed that to 1, probably via the menu (Calculation ribbon). An alternate way to set the value of ORIGIN is to simply write ORIGIN:=... at the top of your sheet which also has the benefit that you immediatly see that the default value is changed. Furthermore you could set any value here, not just 0 and 1 but I can't see much usage for setting a different value - I am used to use the default value 0.
So if you set the desired value via the menu, its not necessary to write ORIGIN:=... in your sheet.

When I write utility programs usually I try to make them ORIGIN-aware so they work as expected whatever the value of ORIGIN in the file might be.

So while "for i:=1 .. rows(M)" works OK only if ORIGIN is set to 1, something like "for i:=ORIGIN .. ORIGIN-1+rows(M)" works OK no matter what the value of ORIGIN is. To make it more compact I assign ORIGIN to a variable O at the start of my programs and use O instead of ORIGIN.

BTW few days ago we had a discussion here in the forum about undocumented Prime functions and we came across the functions "update1(..)" and "update2(...)" which also can be used to insert values in an already existing matrix: