Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline (Pedro)  
#1 Posted : 23 November 2021 20:33:01(UTC)
(Pedro)

Rank: Newbie

Groups: Registered
Joined: 30/01/2021(UTC)
Posts: 6

Hi everyone

I am trying to create a matrix inside a matrix using a for loop.
This is what I did:

Matrix inside a matrix.sm (13kb) downloaded 7 time(s).
Matrix inside a matrix.png

This works but my real data is much larger than the one in this example and it takes like 10 minutes to run. Is there a more efficient way to do this?

Thanks.

Edited by user 23 November 2021 20:46:22(UTC)  | Reason: Not specified

Offline Jean Giraud  
#2 Posted : 23 November 2021 21:35:19(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,800
Canada

Was thanked: 867 time(s) in 697 post(s)
Originally Posted by: (Pedro) Go to Quoted Post
This works but my real data is much larger than the one in this example and it takes like 10 minutes to run. Is there a more efficient way to do this?

Your example runs in 0.5 s [Steam Engine Win 7]

Matrix inside a matrix.sm (13kb) downloaded 6 time(s).

Offline alyles  
#3 Posted : 23 November 2021 23:51:39(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 223
United States

Was thanked: 76 time(s) in 47 post(s)
Two things. One move the assignment of p[k to under the k for loop. You're reassigning to p too often. Also, for large datasets, it helps to initialize the size of the matrix rather than just increasing the size over each iteration. See attaached. Matrix inside a matrix_lyles.sm (16kb) downloaded 9 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
thanks 1 user thanked alyles for this useful post.
on 24/11/2021(UTC)
Offline Razonar  
#4 Posted : 24 November 2021 00:06:24(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 872
Uruguay

Was thanked: 474 time(s) in 307 post(s)
Hola Pedro. Please check this version and tell us how long it takes with your data.

Matrix inside a matrix.sm (32kb) downloaded 12 time(s).

Best regards.
Alvaro.
thanks 1 user thanked Razonar for this useful post.
on 24/11/2021(UTC)
Offline Jean Giraud  
#5 Posted : 24 November 2021 00:54:21(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,800
Canada

Was thanked: 867 time(s) in 697 post(s)
Originally Posted by: alyles Go to Quoted Post
Two things.

On my Win 7 ... takes 4 times my original SS 6179 doctored version.
Has it dependence with Smath version ?
Cheers ... Jean.

Offline Jean Giraud  
#6 Posted : 24 November 2021 01:00:08(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,800
Canada

Was thanked: 867 time(s) in 697 post(s)
Originally Posted by: Razonar Go to Quoted Post
Hola Pedro. Please check this version and tell us how long it takes with your data.

Timing is about twice my doctored version.
Offline (Pedro)  
#7 Posted : 24 November 2021 01:20:04(UTC)
(Pedro)

Rank: Newbie

Groups: Registered
Joined: 30/01/2021(UTC)
Posts: 6

Originally Posted by: alyles Go to Quoted Post
Two things. One move the assignment of p[k to under the k for loop. You're reassigning to p too often. Also, for large datasets, it helps to initialize the size of the matrix rather than just increasing the size over each iteration. See attaached. Matrix inside a matrix_lyles.sm (16kb) downloaded 9 time(s).


Thanks a lot, this works perfectly
Offline (Pedro)  
#8 Posted : 24 November 2021 01:21:22(UTC)
(Pedro)

Rank: Newbie

Groups: Registered
Joined: 30/01/2021(UTC)
Posts: 6

Originally Posted by: Razonar Go to Quoted Post
Hola Pedro. Please check this version and tell us how long it takes with your data.

Matrix inside a matrix.sm (32kb) downloaded 12 time(s).

Best regards.
Alvaro.


Gracias, aprecio tu ayuda
Offline Jean Giraud  
#9 Posted : 24 November 2021 03:51:43(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,800
Canada

Was thanked: 867 time(s) in 697 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Your example runs in 0.5 s [Steam Engine Win 7]

... annotated attachment ...Cheers ... Jean

Matrix inside a matrix (Proposal).sm (32kb) downloaded 12 time(s).
Offline Jean Giraud  
#10 Posted : 25 November 2021 15:15:52(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,800
Canada

Was thanked: 867 time(s) in 697 post(s)
Originally Posted by: (Pedro) Go to Quoted Post
This works but my real data is much larger than the one in this example and it takes like 10 minutes to run. Is there a more efficient way to do this?

1. Wait and see your next Monster Big.
2. 10 min on your machine might take 1 hr on mine, but willing.
3. Maybe not not so big and interpolate ?
See you sometimes, Cheers ... Jean

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