Skip to main content
13-Aquamarine
August 21, 2024
Solved

Loop through matrix values in Mathcad

  • August 21, 2024
  • 1 reply
  • 1691 views

Hello everyone,
in the attached file below, fourth column of matrix I is d1 values.
I want to loop through each d1 values and get R as a matrix.
could someone help me here
attached mathcad 10 file.

Best answer by LucMeekes

I think you want d1 to be the 5th column of matrix I, the one with index 4 (because counting starts at 0).

Well, here goes:

LucMeekes_0-1724242978369.png

And read my extended first answer...

 

Success!
Luc

1 reply

23-Emerald IV
August 21, 2024

If you just want the 4th column values of the matrix I, then you can do that using the column operator:

LucMeekes_0-1724240805721.png

Look in the operators panel for the column operator, or type [Ctrl-c] after the I.

Note that (by default) matrix indexing starts at 0, so the fourth column has index 3.

If you want the function V(d1) applied to that result, then do:

LucMeekes_0-1724241663924.png

Note that you have to vectorise the expression (the arrow above V(I<3>)). The vectorise operator is also found on the operators panel. Its shortcut is [Ctrl-Shft-^].

 

Your function R doesn't do what you might think:

it assigns 0 to i, then loops assigning sequentially, each of the values of the matrix I to VED.

Then within the loop, you assign the full matrix to a row vector with those four variable names.

This means that x gets the value 0 m, Ast gets the value 0 cm2, ...., d1 gets the value 0 cm and n1 gets the value 0.

Note that these (very same!) values are assigned 30 times, because I has 30 elements.

Next thing in the loop is that you re-assign V(d1) to VED, overwriting the initial value of VED.

Now d1 is 0 cm (every time !), and through the function V() that results in 10 mm = 1 cm.

Last thing in the loop is you increase i with 1 (for no use, because you never use its value).

After the loop you return VED.

Well, that's 10 mm = 1 cm,

 

Success!
Luc

13-Aquamarine
August 21, 2024

i think you understood it wrong
i want R values as matrix, which depends on fourth column of Matrix I. 

24-Ruby III
August 21, 2024

Hi,

MartinHanak_0-1724242893857.png