How to input a group of matrix use for loop

How to input a group of matrix use for loop - matrix operation - Messages

#1 Posted: 4/29/2021 1:34:21 AM
hrwang

hrwang

0 likes in 8 posts.

Group: User

I have say, 4 matrix, size of (nr, nz). I am trying to do initiation of these 4 matrix, vs, vb, Cs, Cb. In mathcad, you create a matrix of 4 column and 1 row, representing these 4 matrix, and initiate with for loop.
matrix initiate

Smath didn't show any errors. But when I tried to display the values of one matrix, say, vs=, nothing show up.

I thought Smath might treat all variables as global variable, so, I tried anther way:
2nd try

Then the error showed up, "requested matrix element doesn't exist".

Do I really have to create vs, vb, Cs, Cb before I initiate them?

It is a very simple problem, but I really need help.

By the way, the tutorial is slightly different from reality in "range". When I define for loop ranges, such as [for i "belong" 0..100], the tutorial shows using range2 to choose (0,100), the context will show as above, but the reality will show [for i "belong"[0..100]], a bracket was added. I hope I used the range function properly.

Thanks!


#2 Posted: 4/29/2021 1:59:20 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Hi. SMath matrix index starts at 1, not at 0. If you want to translate Mathcad code into SMath, try to use ORIGIN:=1 in Mathcad, because x[0] always gives an error in SMath.

Best regards.
Alvaro.
#3 Posted: 4/29/2021 3:14:11 AM
hrwang

hrwang

0 likes in 8 posts.

Group: User

Wrote

Hi. SMath matrix index starts at 1, not at 0. If you want to translate Mathcad code into SMath, try to use ORIGIN:=1 in Mathcad, because x[0] always gives an error in SMath.

Best regards.
Alvaro.




Thanks a lot. Following your instructions, I started to initiate from 1, using the 2nd picture, instead of 0. It worked.
#4 Posted: 4/29/2021 8:04:10 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

As side note, you might initialize you matrices even like this:

2021-04-29 13_02_30-SMath Studio - [Worksheet1_].png

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#5 Posted: 4/29/2021 11:05:37 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Then the error showed up, "requested matrix element doesn't exist".
Do I really have to create vs, vb, Cs, Cb before I initiate them?
It is a very simple problem, but I really need help.


That's what you have in my reply

Matrix.PNG
  • New Posts New Posts
  • No New Posts No New Posts