File tree 1 file changed +19
-1
lines changed
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 101
101
102
102
% 4) solve for potential:
103
103
yy= convert2array(fld ); yy= yy(find(KK ~= 0 ));
104
- xx= A \ yy ;
104
+ % Solving A xx = yy
105
+ % Original, but less robust, way to solve A xx = yy
106
+ % is use xx=A\yy;.
107
+ % When matrix A is close to singular, xx may become
108
+ % all zeros. Different versions of MATLAB
109
+ % may have different behaviors. For instance,
110
+ % when using calc_barostream.m (which calls
111
+ % diffsmooth2D_div_inv.m) to calculate barotropic stream function,
112
+ % gcmfaces using matlab/2017b was able to find a solution that
113
+ % appears fine, while matlab/2021a gives a solution
114
+ % of all zeros.
115
+ % xx=A\yy;
116
+ % Use the more robust way to solve yy
117
+ % in a least squares sense. This method
118
+ % can aslo handle sparse matrix and is
119
+ % more efficient than pinv (which cannot handle sparse matrix).
120
+ % Warning is turned on to monitor if the matrix is close to singular.
121
+ xx= lsqminnorm(A ,yy ,' warn' );
122
+
105
123
yyFROMxx= A * xx ;
106
124
107
125
% 5) prepare output:
You can’t perform that action at this time.
0 commit comments