Octave has limited support for nested functions. That is
function y = foo (x) - y = bar(x) + y = bar (x) function y = bar (x) y = ...; end @@ -88,7 +88,7 @@is equivalent to
function y = foo (x) - y = bar(x) + y = bar (x) end function y = bar (x) y = ...; @@ -253,7 +253,7 @@ behaviour, you can enable it since Octave 3.4.0 with the following command: -do_braindead_shortcircuit_evaluation(1) +do_braindead_shortcircuit_evaluation (1)Note that the difference with Matlab is also significant when either argument is a function with side effects or if the first argument @@ -278,7 +278,7 @@ logically true).
Finally, note the inconsistence of thinking of the condition of an if -statement as being equivalent to
all(X(:))
when X is a +statement as being equivalent toall (X(:))
when X is a matrix. This is true for all cases EXCEPT empty matrices:if ([0, 1]) == if (all ([0, 1])) ==> i.e., condition is false. @@ -315,7 +315,7 @@ is equivalent tofunction x = mldivide (A, b) - [Q, R, E] = qr(A); + [Q, R, E] = qr (A); x = [A \ b, E(:, 1:m) * (R(:, 1:m) \ (Q' * b))] end@@ -326,26 +326,26 @@A numerical question arises: how big can the null space component become, relative to the minimum-norm solution? Can it be nicely bounded, or can it be arbitrarily big? Consider this example: - +OctaveFAQ.texi
m = 10; n = 10000; - A = ones(m, n) + 1e-6 * randn(m,n); - b = ones(m, 1) + 1e-6 * randn(m,1); - norm(A \ b) + A = ones (m, n) + 1e-6 * randn (m,n); + b = ones (m, 1) + 1e-6 * randn (m,1); + norm (A \ b)while Octave's minimum-norm values are around 3e-2, Matlab's results are 50-times larger. For another issue, try this code:
m = 5; n = 100; - j = floor(m * rand(1, n)) + 1; - b = ones(m, 1); - A = zeros(m, n); - A(sub2ind(size(A),j,1:n)) = 1; + j = floor (m * rand (1, n)) + 1; + b = ones (m, 1); + A = zeros (m, n); + A(sub2ind (size (A),j,1:n)) = 1; x = A \ b; - [dummy,p] = sort(rand(1,n)); - y = A(:,p)\b; - norm(x(p)-y) + [dummy,p] = sort (rand (1,n)); + y = A(:,p) \ b; + norm (x(p)-y)It shows that unlike in Octave, mldivide in Matlab is not invariant with respect to column permutations. If there are multiple columns of @@ -424,10 +424,10 @@ second case the variable "a" is reset correctly. Therefore Matlab gives no safe way of temporarily changing global variables. -
sin(x)(1:10);
for example is perfectly valid
in Octave but not Matlab. To do the same in Matlab you must do
-y = sin(x); y = y([1:10]);
+y = sin (x); y = y([1:10]);
Indexing other things than variables is possible, as in:
octave:1> [3 1 4 1 5 9](3) ans = 4 - octave:2> cos([0 pi pi/4 7])(3) + octave:2> cos ([0 pi pi/4 7])(3) ans = 0.70711