1 страниц (11 вхождений)
Fill the matrix automatically - Сообщения
#1 Опубликовано: 07.02.2023 09:24:12
Once again I have to ask the Community of Smath Users for help. I hope this is my last struggle with the program.
I would like to create a big matrix M (let's say 1000 x 1000) and fill it with values from other vectors, let's say A and B, as well as some constansts - X and Y.
The pourpose of the matrix is to use it in solving a system of equations, so it should be filled in a very specific way.
The matrix M should look like this (it has zeros, and varied elements from vectors A and B, elements separated with spaces):
| X A1 A1+B1+A2 0 0 ... 0 |
| 0 A2 A2+B2+A3 A3 0 ... 0 |
| 0 0 A3 A3+B3+A4 A4 0 ... 0 |
...
| 0 0 0 ... A999 A999+B999+A1000 A1000 Y|
I tried nested for loops (two loops one for rows and columns) but this way does not allow to put varied values and zeros.
Is there any way I could fill the matrix M automatically?
I would like to create a big matrix M (let's say 1000 x 1000) and fill it with values from other vectors, let's say A and B, as well as some constansts - X and Y.
The pourpose of the matrix is to use it in solving a system of equations, so it should be filled in a very specific way.
The matrix M should look like this (it has zeros, and varied elements from vectors A and B, elements separated with spaces):
| X A1 A1+B1+A2 0 0 ... 0 |
| 0 A2 A2+B2+A3 A3 0 ... 0 |
| 0 0 A3 A3+B3+A4 A4 0 ... 0 |
...
| 0 0 0 ... A999 A999+B999+A1000 A1000 Y|
I tried nested for loops (two loops one for rows and columns) but this way does not allow to put varied values and zeros.
Is there any way I could fill the matrix M automatically?
#2 Опубликовано: 07.02.2023 10:48:30
WroteIs there any way I could fill the matrix M automatically?
Please, attach the vectors c/w the maths of each vector.
As well, once tabulated, described more exploration you desire.
No need to be so immense to reduce timing.
See you soon ... Jean.
#3 Опубликовано: 07.02.2023 11:06:22
Greetings,
If you just want a 'filled in matrix', you can do that easily with the following (copy & paste): this will give you an identity matrix, 1000x1000.
You also have the function: which will provide you a 1000x1000 matrix with 'zeros'.
Hope this helps!
-Kenny Lemens, P.E. ᵂᴵ
WroteIs there any way I could fill the matrix M automatically?
If you just want a 'filled in matrix', you can do that easily with the following (copy & paste):
M:identity(1000)
You also have the function:
M:matrix(1000,1000)
Hope this helps!
-Kenny Lemens, P.E. ᵂᴵ
"No matter where you go, there you are." -Buckaroo BanzaiHotkeys: https://en.smath.com/forum/resource.ashx?a=45771&b=2
#4 Опубликовано: 07.02.2023 13:41:45
WroteI hope this is my last struggle with the program.
Certainly NOT !!! if you continue using Smath.Page7 XyleneMatrix.sm (6 КиБ) скачан 34 раз(а).
Cheers ... Jean.
#5 Опубликовано: 07.02.2023 14:01:34
This algorithm should do it.
Just replace X,Y values and A,B matrices with yours.
Don't know what your 999 row is, so I have improvised.
Regards
fillmatrix.sm (12 КиБ) скачан 27 раз(а).

Just replace X,Y values and A,B matrices with yours.
Don't know what your 999 row is, so I have improvised.
Regards
fillmatrix.sm (12 КиБ) скачан 27 раз(а).
1 пользователям понравился этот пост
sergio 07.02.2023 14:10:00
#6 Опубликовано: 07.02.2023 14:34:25
WroteThis algorithm should do it.
Just replace X,Y values and A,B matrices with yours.
Don't know what your 999 row is, so I have improvised.
Regards
fillmatrix.sm (12 КиБ) скачан 27 раз(а).
I have tried your algorithm on my data and it seems to work. I checked it on a 38 x 38 matrix and it does the job perfectly.
Unfortunatelly I am not able to use it for my purposes because it takes forever to execute for bigger matrices... My final matrix is not 1000 x 1000 - it's 2688 x 2688 and for this matrix the algorithm did not complete for 15 minutes (I have terminated calculations after this time). It did not complete for 1000 x 1000 as well (but in this case I have terminated calculations after 5 minutes). Is there anything I can do to speed it up?
Please find my file with necessary data attached below.
Matrix.sm (105 КиБ) скачан 30 раз(а).
#7 Опубликовано: 07.02.2023 15:32:44
Hi Xylene. First of all, try not to use i if you are going to use complexes, as you would be redefining it, and i is not a protected or special variable, like in Mathcad or other CAS.
Next, notice that in this version of the lasso the opposite of the entire vector is first found, and then the element is selected.

while in this other one the element is first selected and then the opposite is found

Yes, they look the same, but they are not. These improvements bring the code to a few seconds for a few values, but it's still slow for the larger array.
Finally you could try using diag to fill a matrix with the diagonal values, and augment(0,diag(X)) or stack(0,diag(X)) to create subdiagonal or similar matrices and add to the diagonal matrix. In theory that should be the most efficient way to build the Z matrix.
Best regards.
Alvaro
Next, notice that in this version of the lasso the opposite of the entire vector is first found, and then the element is selected.
while in this other one the element is first selected and then the opposite is found
Yes, they look the same, but they are not. These improvements bring the code to a few seconds for a few values, but it's still slow for the larger array.
Finally you could try using diag to fill a matrix with the diagonal values, and augment(0,diag(X)) or stack(0,diag(X)) to create subdiagonal or similar matrices and add to the diagonal matrix. In theory that should be the most efficient way to build the Z matrix.
Best regards.
Alvaro
1 пользователям понравился этот пост
sergio 07.02.2023 15:46:00
#8 Опубликовано: 07.02.2023 17:00:19
WroteIs there anything I can do to speed it up?
Please find my file with necessary data attached below.
Using diag() and submatrices sure speed things up.
Not that fast enough (5 mins), but it finished at least.
Previous solution was still at i=821 after 12 mins when I paused it.
Maybe someone make it even faster, that's all I can do for now.
Here is your file with new algorithm.
Regards
Matrix_diag.sm (114 КиБ) скачан 34 раз(а).
#9 Опубликовано: 07.02.2023 18:38:01
Wrote
Previous solution was still at i=821 after 12 mins when I paused it.
Maybe someone make it even faster, that's all I can do for now.
Maybe this is a silly (and off-topic) question but how can I check on what stage is the program in calculations? Where does that information i = 821 after 12 mins come from?
I know that there is a green progress bar in the bottom right corner, but this bar shows only the number of current operation and not the number of iteration in current operation.
PS pausing the program causes error and results in shuting it down.
#10 Опубликовано: 07.02.2023 19:30:22
Wrotebut how can I check on what stage is the program in calculations?
PS pausing the program causes error and results in shuting it down.
I simply paused it. In debug panel I looked for i value.
It was 821 while time was around 12 minutes at bottom bar.
I use linux, SMath doesn't crash on me when I pause the process.
Monitor your ram usage while running algorithm
That's what come into my mind with info I have.
Regards
PS: I rerun my bad code, it was just past half of your data.
And it took 20 mins to get there, don't use file with for() algorithm.
Use the one with diag(), it completes in 4 minutes.
1 пользователям понравился этот пост
Mark R Harris 08.02.2023 04:22:00
#11 Опубликовано: 08.02.2023 01:41:26
1 пользователям понравился этот пост
Mark R Harris 08.02.2023 04:22:00
1 страниц (11 вхождений)
-
Новые сообщения
-
Нет новых сообщений