How to input a group of matrix use for loop

How to input a group of matrix use for loop - matrix operation - Сообщения

#1 Опубликовано: 29.04.2021 01:34:21
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: 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 Опубликовано: 29.04.2021 01:59:20
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 сообщений из 1674 понравились пользователям.

Группа: 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 Опубликовано: 29.04.2021 03:14:11
hrwang

hrwang

0 сообщений из 8 понравились пользователям.

Группа: 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 Опубликовано: 29.04.2021 08:04:10
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: 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 Опубликовано: 29.04.2021 11:05:37
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений