cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead 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

Using 'for' function to determine all combinations from four sets of variables

ptc-4506064
1-Newbie

Using 'for' function to determine all combinations from four sets of variables

I was wondering if anyone can help me create a programme in MathCAD for the following situation.

I have four matrices

  1. 1 column x 2 rows : variable 1 - representing the length of two members
  2. 2 columns x 3 rows : variable 2 - each column represents three load scenarios associated with two respective members above
  3. 1 column x 3 rows : variable 3 - considers three other load scenarios
  4. 1 column x 2 rows :variable 4- distance at which the values provided in matrix three can act along the members mentioned in matrix 1

Therefore all I want to is do is determine the 18 results that would result from the following equation

M=value+vvariable1*variable2+variable3*variable4

I have been trying to do this using the 'for'' function. Ideally the programme would do the following to detemine the 18 combinations

  1. use first row values from matrices 1 and 4 then
    1. use row 1 of matrix 3 and resolve for the three values in matrix 2
    2. repeat steps above for both rows 2 and 3 of matrix 3
  2. repeat all of step 1 using the second row values from matrices 1 and 4
  3. Output a matrix of results to create either 1x18 matrix or 3x6matrix

I hope this makes sense to some and any help will be appreciated. I have been going around in circles today at work putting off the innevitable of manually doing which would make it look an untidy document.

Many Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

There a some different errors in the sheet which i hav corrected - see attached with remarks

  • As you have changed ORIGIN from default 0 to 1, you have to change the range variables in my routine accordingly
  • The way you had written the local assignment was wrong, every calculalation would overwrite the preceding one and so the routine would return the last value only. Changed the LHS so a 3*6 matrix is returned and provided two alternatives for that
  • P.r is a 3x1 matrix and you treated it as if it were a 3*matrix. I deleted the second vector and left index j - k would be possible, too, here.

Units are no problem here, but you cannot add a lenght and an unitless value. Have corrected page 33, too.

View solution in original post

7 REPLIES 7

Please post a worksheet with your attempts so far. That way we can see which version you are using, don't have to type all in and maybe see better what you are going to attempt.

You can attach files by chosing extended Editor at the upper right.

Can it be you have something like this in mind:

nested_for_1.png

Thank you for the above- it is extremely helpful. However I think I possibly over simplified my explanation because when it came to implementing your solution I have actually got a few more matrices. Please see image attached for the range of values and the equation to be used. Also it also doesn't seem to like units- does it have to be unitless? I don't suppose you could take another look?

For your cross reference in my original post I considered

  • 'val' to be the first line of the equation
  • LEMast to be M1
  • Fmastpp to be M2
  • Pr to be M3
  • d1 to be M4

For the attached situation all other matrices are to match the row in LEmast if they comprise two rows or to match the row in FMastpp if they comprise 3 rows. There should still be 18 combinations.

Matrix+Problem.png

Many thanks

James

Attach the workheet, please. Don't see what error is thrown here.

You calculate x but retruen s!?

Problems with units are possible if you try to assign different units in a matrix.

I have attached the worksheet- the problem that have raised is on page 34 of the worksheet.

Please ignore the one on the previous page as I will fix that once I know how to get the answers for the longer equation.

Many thanks for your help

James

There a some different errors in the sheet which i hav corrected - see attached with remarks

  • As you have changed ORIGIN from default 0 to 1, you have to change the range variables in my routine accordingly
  • The way you had written the local assignment was wrong, every calculalation would overwrite the preceding one and so the routine would return the last value only. Changed the LHS so a 3*6 matrix is returned and provided two alternatives for that
  • P.r is a 3x1 matrix and you treated it as if it were a 3*matrix. I deleted the second vector and left index j - k would be possible, too, here.

Units are no problem here, but you cannot add a lenght and an unitless value. Have corrected page 33, too.

That is amazing- thank you very much for your time and effort.

Top Tags