Stack function

Stack function - Not working as in the Beam.sm example - Сообщения

#1 Опубликовано: 03.05.2013 14:14:46
Danilo Monteiro

Danilo Monteiro

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

Группа: User

I'm creating a worksheet that will draw the forces acting on a beam and calculate reactions, moments, etc.
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.

I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.

The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?

Danilo Monteiro

Stack.png
#2 Опубликовано: 03.05.2013 14:25:14
Davide Carpi

Davide Carpi

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

Группа: Moderator

Wrote

I'm creating a worksheet that will draw the forces acting on a beam and calculate reactions, moments, etc.
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.

I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.

The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?

Danilo Monteiro



It's quite easy; use a 2 arguments stack function and put as first argument the ouput matrix (see the screenshots)

Using a single argument the stack function converts the argument from number to matrix if the argument is a number, otherwise nothing changes.


regards,

w3b5urf3r
SMath Studio - [Page1]_3.png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Dham 03.05.2013 14:51:00
#3 Опубликовано: 03.05.2013 14:49:50
Danilo Monteiro

Danilo Monteiro

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

Группа: User

Wrote

Wrote

I'm creating a worksheet that will draw the forces acting on a beam and calculate reactions, moments, etc.
The worksheet will very similar to the Beam.sm example (but will do some more), and I'm doing pretty much the same that is done there when I don't
have a clue on how to do something.

I'm trying to use the stack function to put all rows of a loop in a single matrix, just like is in Beam.sm, but, the result isn't the same. I attached an image, where in the left side there's the best code I managed to do at the moment (gray), and in the right side is a code which is basically a copy of the code in the example, but using my functions. The code in example only show the last iteration, while my code have a vector of submatrices. None is the desirable answer.

The function in the example creates a single matrix with all the elements of the loops' vector, but it's not doing the same in my worksheet. Does anyone have an idea about why isn't it working?

Danilo Monteiro



It's quite easy; use a 2 arguments stack function and put as first argument the ouput matrix (see the screenshots)

Using a single argument the stack function converts the argument from number to matrix if the argument is a number, otherwise nothing changes.


regards,

w3b5urf3r



Hello, I tried the way you told me, but Smath said that the function is undefined (attached).
But then, I defined a initial matrix and it worked! Thank you very much!


Stack3.png
#4 Опубликовано: 03.05.2013 14:55:42
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hi,

Don't worry... I think that you have forgot to initialize the output matrices

You can create a 2x1 matrix before the for statement (and then after the loop you need to make a submatrix from the 2nd to the last row) or you can add an if/else condition inside the loop that exclude the stack at the first loop (I prefer the second solution but it's matter of taste)

[EDIT]
Wrote

But then, I defined a initial matrix and it worked! Thank you very much!


Good, you're welcome


best regards,

w3b5urf3r
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Dham 03.05.2013 14:59:00
#5 Опубликовано: 03.05.2013 18:21:53
Mike Kaganski

Mike Kaganski

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

Группа: User

Wrote

... or you can add an if/else condition inside the loop that exclude the stack at the first loop ...



No need for that; you only have to initialize the matrix like this:

[MATH lang=eng]Setas:matrix(0,2)[/MATH]
С уважением, Михаил Каганский
4 пользователям понравился этот пост
Davide Carpi 03.05.2013 18:24:00, Radovan Omorjan 03.05.2013 18:35:00, Martin Kraska 03.05.2013 18:51:00, Dham 03.05.2013 20:13:00
#6 Опубликовано: 03.05.2013 18:24:39
Davide Carpi

Davide Carpi

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

Группа: Moderator

Wrote

No need for that; you only have to initialize the matrix like this:

[MATH lang=eng]Setas:matrix(0,2)[/MATH]



Nice solution
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#7 Опубликовано: 03.05.2013 20:16:26
Danilo Monteiro

Danilo Monteiro

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

Группа: User

Wrote

Wrote

No need for that; you only have to initialize the matrix like this:

[MATH lang=eng]Setas:matrix(0,2)[/MATH]



Nice solution



Indeed...

Implemented
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений