Create matrix from predefined cells - vba

Good afternoon,
I'm quite new to VBA and Excel and i'm having the following problem.
I have a function that requires a symmetric matrix as input to calculate the eigenvalue [=MEigenvalueMax (A1: C3)]. However, I have the data for the matrix in different cells. My question is therefore whether there is a function with which I can define predefined cells as a matrix, e. g. =MEigenvalMax ({A1, A2, A3; B1, B2, B3; C1, C2, C3}).
Thank you for the answers!

to fill an array with range values you simply go like follows:
Dim eigenvalueMatrix As Variant
eigenvalueMatrix = Range("A1:C3").Value

Related

Time Complexity of Counting Length of Lists in Adjacency List?

Let's say I have an adjacency list, for example:
A1: b1 b2 b3
A2: b3 b4
A3: b4
A4: b1 b3 b4
What would be the time complexity to find the length of each 'sublist' in the whole adjacency list. The output being:
[A1: 3, A2: 2, A3: 1, A4: 3]
Since it is an adjacency list, I thought it would be O(E+V). But since we're kind of iterating through everything, is it actually O(E*V), like a nested for loop?
Been looking everywhere and I'm still struggling, thanks in advance for your help!
In the end, what you are doing is iterate through the edges. But if there are more vertices than edges, you still iterate through all the vertices. What you are not doing is iterate through all the edges in the graph FOR EVERY vertex.
O(E + V) is just another way of saying O(max(E, V)). So the algorithm is linear, it just means that if you have 1 edge but n vertices, it's still O(n) and not O(1).

How to fill the different elements of a matrix in python

I want to have a 2D Matrix and then fill the elements of this matrix with different values. I know that I need to create a matrix first with the following definition:
Matrix = np.zeros(10,10)
Now my question is how I can fill of the elements of this matrix by a value lets say the element of [4][7] with value of 5. Thanks
Be careful, because the right sintax for a 10x10 matrix filled by zeros is Matrix = np.zeros((10,10)). Then you can simply write in a different line Matrix[4][7] = 5. I advice you to read a tutorial or a introductory book on Python.

Show 2D celldata fields in 3D domains with Paraview

I have a .vtu file composed of tetrahedral and triangular elements (located on an outer surface). I also have a celldata field (for example, nrc1) defined on the triangular elements and being zero in the tetrahedral ones. When I select to plot this field in Paraview, I only see a zero field, corresponding with the 3D elements, but no trace of the field in the 2D elements.
Is there a way to show that 2D field in Paraview?
P.D.: I cannot interpolate the 2D celldata field into a pointdata one, since part of the information (discontinuities,...) would be lost.
There is indeed a conflict between the information on the 3D cells (zeroes) and information on the 2D cells (actual information), where the 2D cells and the 3D cells overlap.
Even though your dataset is valid, mixed dimension dataset are not easy to manage correctly, hence your issue.
In any case, you should extract your 2D cells to be able to visualize your data correctly, here is how I would do it :
Create a new view, click on Spreadsheet view
show your dataset in the spreadsheet view
order by CellType
Manually select all 2D CellType has they will be located together
Add an Extract Selection filter, Apply
You can now visualize your data on this 2D cells only dataset
You could also use Edit->Find Data and select by ID since your cells seems to be ordoned.
Finally, you could write a small Python Programmable Filter to do all that for you completelly automatically, but it is not very easy to implement.

How to traverse all the cells in a 3D CGAL mesh by using BFS?

I have created the 3D mesh. I just wonder whether I can search for the adjacent cells for one special cell.
Given a Cell_handle, you can access its neighbors cells using the neighbor function:
Cell_handle n = cell->neighbor(i); // 0<= i < 4
If you want to restrict to cells in the complex, you can use the function is_in_complex(Cell_handle c).

Avoiding multiplying zeros in matrix solver

Is there a way to avoid multiplying zeros as part of an inner a loop? As a laughable test I tried a conditional to stop the multiplication if it encounters a zero, and of course this is slower then just doing the multiplication. My preference is to leave the LU matrix intact, rather than rearrange to make zeros disappear (sparse). In this instance language is VBA prior to conversion to VB.net.
For k = 1 To i - 1
If LU(j, k) <> 0 and LU(k, i) <> 0 Then temp = temp - LU(j, k) * LU(k, i)
Next k
Thanks.
It is impossible to avoid multiplying by zeroes if you want to preserve the matrix structure.
Furthermore, sparse matrices are not supported in VBA so you would have to code your own class for sparse matrices : the idea is that instead of storing the entire matrix, you just store index/value pairs.
A sparse matrix class would include methods to :
create a matrix with given values in index/value form.
create a sparse matrix from given values in array form.
multiply two sparse matrices (including the special case sparse matrix times sparse vector)
Macroman, I mean to skip the calculation if zeros encountered to speed up solution. Thanks.
Titus, already wrote a fully pivoted LUD solver for VBA which can (slowly) solve sparse matrices. I just wanted to see if it was feasible to convert solver to Sparse techniques. Memory is not an issue, hence preference to avoid index/value storage technique, so I just wanted see if there was a fast way to make solver skip zeros to speed it up. Thanks.