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 ianlh  
#1 Posted : 02 December 2021 18:39:56(UTC)
ianlh


Rank: Advanced Member

Groups: Registered
Joined: 18/12/2014(UTC)
Posts: 38

Hi,

Is there a built in function that can get the sum of the upper secondary diagonals of a matrix? some times called the skew:

skew.JPG

I can call each by its element, but I would like it to work for any a1n & an1, I can do tr(reverse) to find the secondary diagonal, after each reduction of the matrix by 1 row/column:
Diagonals.JPG
Diagonals2.JPG

matrix multiplier.sm (16kb) downloaded 10 time(s).

Thanks in advance
Ian


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

Offline ianlh  
#2 Posted : 02 December 2021 21:23:54(UTC)
ianlh


Rank: Advanced Member

Groups: Registered
Joined: 18/12/2014(UTC)
Posts: 38

Lets say the matrix is 10 x 10, I don't want the user to have to "manually" create all the steps to get to the tr(reverse), this is a lot of work and could introduce errors. What I want is a simple (if it is indeed simple!) loop to do it.
Your solutions certainly speed up the process and wonder if they could be implemented?

Ian
Offline CBG  
#3 Posted : 02 December 2021 23:33:19(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 308

Was thanked: 77 time(s) in 58 post(s)
Hello

Maybe you can do this

Matrix_M.png


Best Regards

Carlos
Offline Davide Carpi  
#4 Posted : 02 December 2021 23:42:55(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1329 time(s) in 875 post(s)
skew.sm (7kb) downloaded 11 time(s).Screenshot_20211202_225011.jpg

(the first is more a "proof of concept", is very inefficient because it does a lot useless calculations)

Edited by user 03 December 2021 01:14:25(UTC)  | Reason: minor improvement, DPI screenshot scaled

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline ianlh  
#5 Posted : 03 December 2021 12:03:45(UTC)
ianlh


Rank: Advanced Member

Groups: Registered
Joined: 18/12/2014(UTC)
Posts: 38

Originally Posted by: Jean Giraud Go to Quoted Post
... your image red arrows represents the *.JPEG destruction.
JPG does not compress, it destroys the details bottom-right up top left.
What's the relationship between your JPG image and your attempt ?

Image jpeg.sm (54kb) downloaded 5 time(s).


Hi Jean,

The image was just to illustrate the direction of the summation, the primary diagonal is top left to bottom right.

Hi Carlos and Davide,

These look like interesting solutions, let me try on the larger matrix.

Thanks once again
Ian
Offline ianlh  
#6 Posted : 03 December 2021 12:53:44(UTC)
ianlh


Rank: Advanced Member

Groups: Registered
Joined: 18/12/2014(UTC)
Posts: 38

Interesting results on the speed of calculation:
Main Matrix:
wind 1.JPG
Method Carlos:
wind 2.JPG
Method Davide:
wind 3.JPG
Comments?
Offline Davide Carpi  
#7 Posted : 03 December 2021 14:06:03(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
(the first is more a "proof of concept", is very inefficient because it does a lot useless calculations)


You should try the 2nd method in my file.
As stated in the previous post the first method is really inefficient, since for each iteration it calculates all the sums from the first value up to the n-th diagonal.

BTW with a random set of values and small matrices, doesn't seems so slow in my machine (WIN7PRO/AMD PRO A10/16GB RAM). With bigger matrices the difference is huge (for a 100x100 matrix, 26.1s with first method, 0.028s with second method)

2021-12-03 13_23_51-SMath Solver - [skew.sm_].png



The method to check the sum of [r,c] coordinates can be used more efficently in a double loop, though (here it is extended to the whole matrix).

2021-12-03 12_14_18-SMath Solver - [skew.sm_].png

Edited by user 03 December 2021 15:38:35(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
Offline ianlh  
#8 Posted : 03 December 2021 17:51:14(UTC)
ianlh


Rank: Advanced Member

Groups: Registered
Joined: 18/12/2014(UTC)
Posts: 38

Hi,

Second method now as quick as the first by Carlos.

Jean, many opportunities for engineering!

Thanks to all

Ian
Offline Jean Giraud  
#9 Posted : 04 December 2021 03:18:32(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: ianlh Go to Quoted Post
Jean, many opportunities for engineering !

w/o abstract: of little interest for common visitor.

Matrix DIAGONAL.sm (12kb) downloaded 10 time(s).



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.