Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed u & sigma to correspond w/ MATLAB code #3

Closed
wants to merge 1 commit into from

Conversation

benjoch
Copy link
Collaborator

@benjoch benjoch commented Jun 22, 2021

When looking at the sqrt(1/sigma) problem I referenced the MATLAB code and noticed differences between the MATLAB and R functions. Namely:

  • [U, SIGMA] = eig() in MATLAB will return a matrix of the right eigenvectors to U and a diagonal matrix of the eigenvalues to SIGMA. So our 'u' in the R script should correspond to the eigenvectors and our 'sigma' to the eigenvalues
  • diag() in MATLAB will return a column vector of the main diagonal elements of A when given a square matrix so since SIGMA is a diagonal matrix of eigenvalues in MATLAB diag(SIGMA) returns a column vector of the eigenvalues. In the R script, eigendecomp$values returns a vector of the eigenvalues not a diagonal matrix of the eigenvalues so the diag() call is not needed in R

However, after making these fixes I still had the same issue with sqrt(1/sigma) which I am working on. Let me know if I'm making a dumb mistake here. Also here's the MATLAB documentation about the functions that I referenced:
eig() - https://www.mathworks.com/help/matlab/ref/eig.html#d123e352209
diag() - https://www.mathworks.com/help/matlab/ref/diag.html

When looking at the sqrt(1/sigma) problem I referenced the MATLAB code and noticed differences between the MATLAB and R functions. Namely:

- [U, SIGMA] = eig() in MATLAB will return a matrix of the right eigenvectors to U and a diagonal matrix of the eigenvalues to SIGMA. So our 'u' in the R script should correspond to the eigenvectors and our 'sigma' to the eigenvalues 
- diag() in MATLAB will return a column vector of the main diagonal elements of A when given a square matrix so since SIGMA is a diagonal matrix of eigenvalues in MATLAB diag(SIGMA) returns a column vector of the eigenvalues. In the R script, eigendecomp$values returns a vector of the eigenvalues not a diagonal matrix of the eigenvalues so the diag() call is not needed in R

However, after making these fixes I still had the same issue with sqrt(1/sigma) which I am working on.  Let me know if I'm making a dumb mistake here. Also here's the MATLAB documentation about the functions that I referenced:
eig() - https://www.mathworks.com/help/matlab/ref/eig.html#d123e352209
diag() - https://www.mathworks.com/help/matlab/ref/diag.html
@thisjustinh
Copy link
Owner

Very good catch; I'll make these changes in my code and push my stuff now however so this branch won't be merged.

With these changes the values for fx and fy start to directly match what I'm getting in MATLAB but like you say the negative sqrt is still problematic.

@thisjustinh thisjustinh deleted the benjoch-patch-1 branch June 22, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants