Gauss seidel in VBA
Trying to use Gauss seidel method to solve a 25 by 25 matrix to solve a 2D heat transfer chemical engineering problem.
But it doesnt go to 2nd iteration
Do While error > 0.1
temps0 = temps1(UBound(matrix1, 1), 1) ' Old temperature for error calculation
'Conducts the gauss algorithm for each row
For i = 1 To UBound(matrix1, 1)
temps1(i, 1) = matrix1(i, UBound(matrix1, 2))
For j = 1 To (UBound(matrix1, 2)  1)
If j <> i Then
temps1(i, 1) = temps1(i, 1)  (matrix1(i, j) * temps1(j, 1))
ElseIf j = i Then
divider = matrix1(i, j)
End If
Next j
temps1(i, 1) = temps1(i, 1) / divider
Next i
error = Abs((temps1(UBound(matrix1, 1), 1)  temps0) / temps1(UBound(matrix1, 1), 1))
iteration = iteration + 1
Loop
this is the do while loop for Gauss Seidel Matrix1 is coeff matrix generated by previous functions
Really appreciate any help. TY
1 answer

Problem solved by change the value of error, thanks anyway
See also questions close to this topic

Getting a more useful/accurate error message
We have an issue with an Access frontend that seemingly randomly but constantly times out users with no explanation. This has been a longstanding issue, each time the disconnect happens we're provided with the sub that's causing the issue and a generic error message.
I'm starting to think the error message is misleading, it gives a generic "Connection Failure" with an Error Code of 0. After Googling the code that apparently means no error occurred?
I use C# not VBA so I'm not familiar with it but the error handling is as follows:
Private Sub Form_Timer() Dim blnSystemMaintenance As Boolean On Error GoTo ErrHand ' Check for System Maintenance. blnSystemMaintenance = DLookup("SystemMaintenance", "ConfigItems") If blnSystemMaintenance Then //Do stuff Else //Do stuff End If //Do stuff End If ErrExit: Exit Sub Resume ErrHand: ' If Err.Number = 1 Then ' Else MsgBox "Error number: " & Err.Number & vbCrLf & _ "Error description: " & Err.Description, vbCritical, _ "Unexpected Error Occurred in Sub: Form_Timer" Resume ErrExit ' End If End Sub
Is there a way to get a more helpful error message?

Can't add item to combobox (form control) in vba excel
I have several ComboBoxes (form control) on
sheet1
. I would like to loop through and populate them. Nothing happens, no error or no items in the list of each ComboBox. I use this code:Sub cmbBox() Dim ctrl As Shape For Each ctrl In Sheet1.Shapes If ctrl.Type = msoOLEControlObject Then ctrl.AddItem "Done" ctrl.AddItem "Not Done" End If Next End Sub

Input box with default value (excel VBA)
I tried the
InputBox
for the "period" which is the month ("m"), and it worked. But now I tried using it for the "year" ("YYYY"), and it does not function as expected.Here is my code for the "year" (same as in "period", only different values and variables):
Dim VYear as variant Dim defY as variant defY = Format(DateAdd("YYYY", 0, Now), "YYYY") VYear = InputBox("Year covered","Year",defY) If VYear > 2014 And VYear < defY Then Range("I1").Value = VYear ElseIf VYear = "" Then Exit Sub Else Do Until VYear > 2014 And VYear < defY MsgBox "Please enter a year not earlier than 2015 and not later than this year" VYear = InputBox("Year covered") Loop End If
Well, it does give me the default value of
2018
, but when I tried entering wrong values, it would proceed with the message inMsgBox
(as expected), but it would no longer accept ANY values, even the year today (2018
).Cycle goes like:
MsgBox
(Please enter....) thenInputBox
thenMsgBox
again...What could have caused the error?
PS. I intentionally used
As Variant
so that even though users input letters, it won't give the error of "type mismatch". 
LAPACK matrix inversion: unable to program
I am developing embedded software on ARM CortexA53 (armv7/v8) for image processing, and I need some help for a specific algorithm.
This later involves complex (real/imaginary parts) matrix inversion with large size (up to 24x24). The most significant constraint is the timing execution.
I am currently looking for a library, optimized for ARM (using NEON SIMD?), which offers this kind of operation (matrix inversion of large size, with complex numbers).
I did try Eigen library: it works fine, but it is too slow. Our processor runs at 1 GHz, and I got an average duration of 0,82 ms for a complex double matrix inversion of size 24x24.
I also had a look at:
 Ne10 library: it does not propose matrix inversion with complex number (no template used) and large size (maximum size is 4x4).
 ARM Compute Library: cannot find matrix inversion function. I am not sure it is implemented.
 ARM Performance Libraroes: I am still looking for the matrix inversion, does anyone knows which function/class I should have a look to?
Please, any C++ libraries (should be templated for use of complex), optimized for ARM, could you suggest?
Thanking you in advance!
Laurent.
UPDATE
I am currently testing the C LAPACK (=LAPACKE) library to complete a matrix inversion.
I do have problem to link my code. Look at C++ code (example of code got from internet, very simple):
#include "test_lapacke.hh" extern "C" { #include <lapacke.h> } lapack_int matInv(double *A, unsigned n) { int ipiv[n+1]; lapack_int ret; ret = LAPACKE_dgetrf(LAPACK_COL_MAJOR, n, n, A, n, ipiv); if (ret !=0) return ret; ret = LAPACKE_dgetri(LAPACK_COL_MAJOR, n, A, n, ipiv); return ret; } /**********************************************************************************************************************/ void Test_lapacke() { double A[] = { 0.378589, 0.971711, 0.016087, 0.037668, 0.312398, 0.756377, 0.345708, 0.922947, 0.846671, 0.856103, 0.732510, 0.108942, 0.476969, 0.398254, 0.507045, 0.162608, 0.227770, 0.533074, 0.807075, 0.180335, 0.517006, 0.315992, 0.914848, 0.460825, 0.731980 }; for (int i=0; i<25; i++) { if ((i%5) == 0) putchar('\n'); printf("%+12.8f ",A[i]); } putchar('\n'); matInv(A,5); for (int i=0; i<25; i++) { if ((i%5) == 0) putchar('\n'); printf("%+12.8f ",A[i]); } putchar('\n'); }
I did add all blas/lapack libraries to C++ linker on my project:
llapack llapacke lrefblas lcblas ltmglib
But I still got the error:
/path/lib/liblapacke.a(lapacke_dgetrf_work.o): In function
LAPACKE_dgetrf_work': lapacke_dgetrf_work.c:(.text+0xd8): undefined reference to
dgetrf_' lapacke_dgetrf_work.c:(.text+0x160): undefined reference todgetrf_' /path/lib/liblapacke.a(lapacke_dgetri_work.o): In function
LAPACKE_dgetri_work': lapacke_dgetri_work.c:(.text+0xe4): undefined reference todgetri_' lapacke_dgetri_work.c:(.text+0x174): undefined reference to
dgetri_' collect2: error: ld returned 1 exit status make: *** [Test_matrice] Erreur 1Any ideas to solve this?
Many thanks! Regards, Laurent.

R  Comparing datas of two data.frames with a loop, constant by constant
Basically, I want to compare the same constants (same [X,Y] values) from two data frames and applied them a few operations afterward, before stocking the result in a new data frame. The tricky part is that I need to treat all the values of these data frames. In other words, I need to compare the value of dataA[1,1] with dataB[1,1] and if they respect certain conditions, I'll perform an operation, else another opeartion, then stock the result in a new data.frame. After, rinse and repeat for dataA[1,2] and dataB[1,2] up to dataA[100,100] and dataB[100,100].
Obviously, I've to use a loop here (and some if/else), but I can't seems to figure out the proper structure. Being used to php, I tried the foreach package in R, but it only return FALSE (and it do so in vector format instead of a matrix with multiple columns). If I do the operation by hand, there are more TRUE than FALSE, so obviously, something's wrong here :
x < foreach(dataIDH, dataPIB) %do% { if (dataPIB <= dataIDH+5 & dataPIB >= rankIDH5) { x < mean(dataPIB, dataIDH) } else { x < FALSE} } x
I did tried a for loop, but I'm simply unable to put the results in a data.frame (even less a ones that match the layout of the dataframes used here, which I need to do) :
x < for(idh in 1:nrow(dataIDH)) { for(idh in 1:ncol(dataIDH)) { for(pib in 1:nrow(dataPIB)) { for(pib in 1:ncol(dataPIB)) { if (pib<=idh+5 & pib>=idh5) { x < mean(pib,idh) } else { x < FALSE} } } } } x
For informations : the data frames contain numeric values for a set of countries (rows) for a few years (columns).
Any ideas on how to get out of this mess?
Edit 1 : an extract of the two dataframes used (1st row and col displayed here are actually headers) :
dataIDH
CountryCode,2005,2006,2007,2008 AFG,14,14,16,16 ALB,100,98,99,98 DZA,85,86,90,86
dataPIB
CountryCode,2005,2006,2007,2008 AFG, 69, 18, 70, 71 ALB, 102, 98, 97, 63 DZA, 85, 89, 91, 137
Edit 2 : and the final result should be a new data.frame, on the same layout:
x
CountryCode,2005,2006,2007,2008 AFG, FALSE, 16, FALSE, FALSE ALB, 101, 98, 98, FALSE DZA, 85, 87.5, 90.5, FALSE

Speed up matrix operations
I have two matrices of the same dimensions (which in reality are of 2,500 x 15,000):
set.seed(1) a.mat < matrix(rnorm(25*150),nrow=25,ncol=150,dimnames=list(paste0("p",1:25),paste0("c",1:150))) b.mat < matrix(rnorm(25*150),nrow=25,ncol=150,dimnames=list(paste0("p",1:25),paste0("c",1:150)))
And I'm computing this with them:
res.mat < do.call(cbind,lapply(1:ncol(a.mat),function(i){ t.mat < a.mata.mat[,i] t.mat < log10(abs(t.mat)+1) * sign(t.mat) return(suppressWarnings(cor(t.mat,b.mat[,i]))) }))
Any idea if and how this can done faster than the way I'm currently doing it? Perhaps running it in parallel with
multidplyr
?Per `multidplyr, here's what I'm attempting:
library(dplyr) df < do.call(rbind,lapply(1:ncol(a.mat),function(i){ cbind(reshape2::melt(a.mat) %>% dplyr::rename(id=Var1,cell=Var2,a.value=value), do.call("rbind",replicate(ncol(a.mat),data.frame(cell.i=colnames(a.mat)[i],a.value.i=a.mat[,i]),simplify=F)), do.call("rbind",replicate(ncol(a.mat),data.frame(b.value.i=b.mat[,i]),simplify=F))) })) %>% dplyr::mutate(t.value=a.valuea.value.i) %>% dplyr::mutate(t.value=log10(abs(t.value)+1)*sign(t.value)) %>% dplyr::group_by(cell.i)
And then:
group.size < 3 n.groups < ceiling(ncol(a.mat)/group.size) for(i in 1:n.groups){ start.idx < (i1)*group.size+1 end.idx < min(i*group.size,ncol(a.mat)) current.df < df %>% dplyr::filter(cell.i %in% colnames(a.mat)[start.idx:end.idx]) current.df < current.df %>% multidplyr::partition(cell.i) %>% multidplyr::cluster_library("tidyverse") %>% multidplyr::cluster_library("MASS") %>% multidplyr::cluster_assign_value("myFunction", myFunction) %>% do(results = myFunction(.)) %>% dplyr::collect() %>% .$results %>% dplyr::bind_rows() }
Where:
myFunction < function(df) { return(df %>% dplyr::group_by(e.cell) %>% dplyr::mutate(cor=cor(t.value,b.value.i))) }
However, this hits this error message:
Error in checkForRemoteErrors(lapply(cl, recvResult)) : 3 nodes produced errors; first error: Can't convert an environment to function Call `rlang::last_error()` to see a backtrace In addition: Warning message: group_indices_.grouped_df ignores extra arguments
So, is using
multidplyr
this way even worth it? and if so any idea what I'm doing wrong here?