Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Dham  
#1 Posted : 03 May 2013 21:14:46(UTC)
Dham


Rank: Member

Groups: Registered
Joined: 25/06/2012(UTC)
Posts: 14
Man
Brazil
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):
Stack.png

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 03 May 2013 21:25:14(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,649
Man
Italy
Location: Italy

Was thanked: 1333 time(s) in 877 post(s)
Originally Posted by: Dham Go to Quoted Post
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):
SMath Studio - [Page1]_2.png
SMath Studio - [Page1]_3.png
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 03/05/2013(UTC)
Offline Dham  
#3 Posted : 03 May 2013 21:49:50(UTC)
Dham


Rank: Member

Groups: Registered
Joined: 25/06/2012(UTC)
Posts: 14
Man
Brazil
Location: Rondonópolis

Originally Posted by: w3b5urf3r_reloaded Go to Quoted Post
Originally Posted by: Dham Go to Quoted Post
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).Wallbash
But then, I defined a initial matrix and it worked! Thank you very much! Victory

Dham attached the following image(s):
Stack2.png
Stack3.png
Offline Davide Carpi  
#4 Posted : 03 May 2013 21:55:42(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,649
Man
Italy
Location: Italy

Was thanked: 1333 time(s) in 877 post(s)
Hi,

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

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 Go to Quoted Post
But then, I defined a initial matrix and it worked! Thank you very much! Victory

Good, you're welcome Good


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
thanks 1 user thanked Davide Carpi for this useful post.
on 03/05/2013(UTC)
Offline mikekaganski  
#5 Posted : 04 May 2013 01:21:53(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: w3b5urf3r_reloaded Go to Quoted Post
... 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
thanks 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)
Offline Davide Carpi  
#6 Posted : 04 May 2013 01:24:39(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,649
Man
Italy
Location: Italy

Was thanked: 1333 time(s) in 877 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
No need for that; you only have to initialize the matrix like this:

Setas:matrix(0,2)


Nice solution Friends
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Dham  
#7 Posted : 04 May 2013 03:16:26(UTC)
Dham


Rank: Member

Groups: Registered
Joined: 25/06/2012(UTC)
Posts: 14
Man
Brazil
Location: Rondonópolis

Originally Posted by: w3b5urf3r_reloaded Go to Quoted Post
Originally Posted by: mikekaganski Go to Quoted Post
No need for that; you only have to initialize the matrix like this:

Setas:matrix(0,2)


Nice solution Friends


Indeed...

Implemented Biggrin
Users browsing this topic
Guest
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.