Skip to content

Commit 4bb4597

Browse files
author
Crouse
committed
Bug fixes.
1 parent a703dc7 commit 4bb4597

5 files changed

Lines changed: 91 additions & 14 deletions

File tree

Coordinate_Systems/lineOfSightHitsEarth.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@
146146
end
147147
else
148148
%Neither the starting nor the ending points are on the ground.
149-
if((t(1)<0||t(1)>1)&&(t(2)<0||t(2)>1))
150-
%The line of sight never hits thr ground.
149+
if(isempty(t)||(t(1)<0||t(1)>1)&&(t(2)<0||t(2)>1))
150+
%The line of sight never hits the ground.
151151
typeOfHit=0;
152152
else
153-
%The line of sight hits th gorund somewhere.
153+
%The line of sight hits the ground somewhere.
154154
typeOfHit=1;
155155
end
156156
end

Mathematical_Functions/Basic_Matrix_Operations/Shared_C++_Code/basicMatOpsEigen.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ TEig MatrixOfVal(const TVal val,const size_t numRows, const size_t numCols) {
7979
* 2 Use std::numeric_limits<double>::epsilon()*norm(A,1).
8080
* 3 Use max(size(A))*std::numeric_limits<double>::epsilon()*max(s).
8181
* U,s,V These are returned as the left (U) and right (V) singular
82-
* vectors (computed thin) and a vector of the singular values.
82+
* vectors (not computed thin) and a vector of the singular
83+
* values.
8384
*
8485
*OUTPUTS: The return value is the rank. The outputs of the SVD performed
8586
* in computing the rank are put in U, s, and V for reuse
@@ -114,7 +115,7 @@ size_t matrixRank(const T &X, const int algorithm,T &U, Eigen::MatrixXd &s, T &V
114115
return 0;
115116
}
116117

117-
Eigen::JacobiSVD<T> svdX(X, Eigen::ComputeThinU | Eigen::ComputeThinV);
118+
Eigen::JacobiSVD<T> svdX(X, Eigen::ComputeFullU | Eigen::ComputeFullV);
118119
//The singular values are already sorted in decreasing order.
119120
s=svdX.singularValues();
120121
U=svdX.matrixU();

Mathematical_Functions/Basic_Matrix_Operations/matrixRank.cpp

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray
2626
return;
2727
}
2828

29-
if(nlhs>1) {
29+
if(nlhs>4) {
3030
mexErrMsgTxt("Invalid number of outputs.");
3131
return;
3232
}
3333

34-
if(nrhs>1) {
34+
if(nrhs>1&&!mxIsEmpty(prhs[1])) {
3535
algorithm=getIntFromMatlab(prhs[1]);
3636
}
3737

@@ -53,6 +53,45 @@ void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray
5353
Eigen::MatrixXd s;
5454

5555
theRank=matrixRank<Eigen::MatrixXcd>(XEigen, algorithm, U, s, V);
56+
57+
plhs[0]=sizeTMat2MatlabDoubles(&theRank,1,1);
58+
59+
const size_t numRowU=U.rows();
60+
const size_t numColU=U.cols();
61+
const size_t numRowV=V.rows();
62+
const size_t numColV=V.cols();
63+
const size_t numElsS=s.size();
64+
65+
if(nlhs>1) {
66+
mxArray *VMat=mxCreateNumericMatrix(numRowV,numColV,mxDOUBLE_CLASS,mxCOMPLEX);
67+
std::complex<double> *VData=reinterpret_cast<std::complex<double>*>(mxGetComplexDoubles(VMat));
68+
69+
for(size_t i=0;i<numRowV*numColV;i++) {
70+
VData[i]=V(i);
71+
}
72+
plhs[1]=VMat;
73+
74+
if(nlhs>2) {
75+
mxArray *UMat=mxCreateNumericMatrix(numRowU,numColU,mxDOUBLE_CLASS,mxCOMPLEX);
76+
std::complex<double> *UData=reinterpret_cast<std::complex<double>*>(mxGetComplexDoubles(UMat));
77+
78+
for(size_t i=0;i<numRowU*numColU;i++) {
79+
UData[i]=U(i);
80+
}
81+
plhs[2]=UMat;
82+
83+
if(nlhs>3) {
84+
mxArray *SMat=mxCreateNumericMatrix(numElsS,numElsS,mxDOUBLE_CLASS,mxREAL);
85+
double *SData=mxGetDoubles(SMat);
86+
memset(SData,0,sizeof(double)*numElsS);
87+
88+
for(size_t i=0;i<numElsS;i++) {
89+
SData[i*numElsS+i]=s(i);
90+
}
91+
plhs[3]=SMat;
92+
}
93+
}
94+
}
5695
} else {
5796
double *X=mxGetDoubles(prhs[0]);
5897
const Eigen::Map<Eigen::MatrixXd> XEigen(X,M,N);
@@ -61,9 +100,46 @@ void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray
61100
Eigen::MatrixXd s;
62101

63102
theRank=matrixRank<Eigen::MatrixXd>(XEigen, algorithm, U, s, V);
103+
104+
plhs[0]=sizeTMat2MatlabDoubles(&theRank,1,1);
105+
106+
const size_t numRowU=U.rows();
107+
const size_t numColU=U.cols();
108+
const size_t numRowV=V.rows();
109+
const size_t numColV=V.cols();
110+
const size_t numElsS=s.size();
111+
112+
if(nlhs>1) {
113+
mxArray *VMat=mxCreateNumericMatrix(numRowV,numColV,mxDOUBLE_CLASS,mxREAL);
114+
double *VData=mxGetDoubles(VMat);
115+
116+
for(size_t i=0;i<numRowV*numColV;i++) {
117+
VData[i]=V(i);
118+
}
119+
plhs[1]=VMat;
120+
121+
if(nlhs>2) {
122+
mxArray *UMat=mxCreateNumericMatrix(numRowU,numColU,mxDOUBLE_CLASS,mxREAL);
123+
double *UData=mxGetDoubles(UMat);
124+
125+
for(size_t i=0;i<numRowU*numColU;i++) {
126+
UData[i]=U(i);
127+
}
128+
plhs[2]=UMat;
129+
130+
if(nlhs>3) {
131+
mxArray *SMat=mxCreateNumericMatrix(numElsS,numElsS,mxDOUBLE_CLASS,mxREAL);
132+
double *SData=mxGetDoubles(SMat);
133+
memset(SData,0,sizeof(double)*numElsS);
134+
135+
for(size_t i=0;i<numElsS;i++) {
136+
SData[i*numElsS+i]=s(i);
137+
}
138+
plhs[3]=SMat;
139+
}
140+
}
141+
}
64142
}
65-
66-
plhs[0]=sizeTMat2MatlabDoubles(&theRank,1,1);
67143
}
68144

69145
/*LICENSE:

Mathematical_Functions/Basic_Matrix_Operations/matrixRank.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
%
1515
%OUTPUTS: rankVal The rank of matrix A.
1616
% V The right singular vectors from the SVD used here (The
17-
% SVD is computed with the 'econ' option). Given the rank,
18-
% one can extract a basis or a nullspace.
17+
% full SVD is computed, not the 'econ' or 0 options). Given
18+
% the rank, one can extract a basis or a nullspace.
1919
% U The left singular vectors from the SVD.
2020
% S A diagonal matrix of singular values from the SVD.
2121
%
@@ -34,9 +34,9 @@
3434
end
3535

3636
if(nargout>1)
37-
[U,S,V]=svd(A,'econ');
37+
[U,S,V]=svd(A);
3838
else
39-
[~,S,~]=svd(A,0);
39+
[~,S,~]=svd(A);
4040
end
4141
s=diag(S);
4242

Mathematical_Functions/Polynomials/Generic_Multivariate_Polynomials/polyRootsMultiDim.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
if(useMotzkinNull)
236236
XY=MotzkinMatrix([N1*Z,N2]);
237237
else
238-
XY=null([N1*Z,N2]);
238+
XY=nullspace([N1*Z,N2]);
239239
end
240240
numZPrev=size(Z,2);
241241
X=XY(1:numZPrev,:);

0 commit comments

Comments
 (0)