Rank: Member Groups: Registered
Joined: 25/06/2012(UTC) Posts: 14 Location: Rondonópolis
|
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 Dham attached the following image(s):
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,650 Location: Italy Was thanked: 1334 time(s) in 877 post(s)
|
Originally Posted by: Dham 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 Edited by user 03 May 2013 21:30:56(UTC)
| Reason: Not specified Davide Carpi attached the following image(s): |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Member Groups: Registered
Joined: 25/06/2012(UTC) Posts: 14 Location: Rondonópolis
|
Originally Posted by: w3b5urf3r_reloaded Originally Posted by: Dham 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! Dham attached the following image(s):
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,650 Location: Italy Was thanked: 1334 time(s) in 877 post(s)
|
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]Originally Posted by: Dham But then, I defined a initial matrix and it worked! Thank you very much! Good, you're welcome best regards, w3b5urf3r Edited by user 03 May 2013 21:58:18(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
1 user thanked Davide Carpi for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 17/01/2013(UTC) Posts: 296 Location: Khabarovsk, Russia Was thanked: 151 time(s) in 107 post(s)
|
Originally Posted by: w3b5urf3r_reloaded ... 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: Setas:matrix(0,2) |
Best regards, Mike Kaganski |
4 users thanked mikekaganski for this useful post.
|
on 04/05/2013(UTC), on 04/05/2013(UTC), on 04/05/2013(UTC), on 04/05/2013(UTC)
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,650 Location: Italy Was thanked: 1334 time(s) in 877 post(s)
|
Originally Posted by: mikekaganski No need for that; you only have to initialize the matrix like this:
Setas:matrix(0,2) Nice solution |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
|
|
|
Rank: Member Groups: Registered
Joined: 25/06/2012(UTC) Posts: 14 Location: Rondonópolis
|
Originally Posted by: w3b5urf3r_reloaded Originally Posted by: mikekaganski No need for that; you only have to initialize the matrix like this:
Setas:matrix(0,2) Nice solution Indeed... Implemented
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.