Re: Which computer language program is best for undergrads?



Christian Gollwitzer wrote:
A more serious example would be

function p=llsq(A, y, B, c)
% solve the linear least squares problem
% with equality constraints
% min | A p - y | , B p = c

[H, R] = qr(B');
R = R(1:rows(B),:);
AH = A*H;
A1 = AH(:, 1:rows(B));
A2 = AH(:, rows(B)+1:columns(A));
y1=R'\c;
r=A1*y1;
yt = y - r;
z = A2 \ yt;
p = H* [y1; z];
end

which solves a specially LSQ problem. If you compare it to the paper I'm
now lazy to search, you will find that this is an almost verbatim
transliteration of the maths from there.

Again, that relies upon basic features found in many modern languages.

High-level languages IMHO are those that provide datastructures like
lists, matrices, strings... as primitive datatypes together with the
elementary operations.

High-level languages also automate basic functionality like memory
management which, as I understand it, Matlab does not.

I'm not sure what you mean by memory management (GC?). Matlab doesn't have
pointers and you never allocate memory on the heap. Just use your
matrices, cell arrays (=heterogeneous lists in FL speak) as you like and
the memory is allocated automatically.

Matlab does not automate the collection of unused memory, it simply leaks
until it dies or the user explicitly frees memory:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/brh72ex-25.html

That is a hallmark of a low level language and it puts Matlab decades behind
the current state-of-the-art concurrent GCs that underpin the JVM and CLR.

In Matlab you perform matrix operations in symbolic notation like you
would do on paper. Numeric algorithms can often be expressed concisely.

Can a language be high-level if it is good at matrix computations at the
cost of all else?

Some high-level languages are very specialized - take SQL.

I believe you are using a broken definition of "high level". If you take
your definition to the extreme then even the most minimal language (e.g.
Brainf*ck) that lacks almost all modern features is "high level" because it
can do one specialized thing adequately.

Look at The MathWorks' own red-black tree insertion function:

global bt_nil rb_black rb_red

current=rb.tree;
parent=0;
while current~=bt_nil
if key==current.key
return;
end
parent=current;
if key<current.key
current=current.left;
else
current=current.right;
end
end

X=pointer;
X.data=data;
X.key=key;
X.parent=parent;
X.left=bt_nil;
X.right=bt_nil;
X.color=rb_red;

if parent~=0
if key<parent.key
parent.left=X;
rb.size=rb.size+1;
else
parent.right=X;
rb.size=rb.size+1;
end
else
rb.tree=X;
end

while (X~=rb.tree) && (X.parent.color==rb_red)
if X.parent==X.parent.parent.left
Y=X.parent.parent.right;
if Y.color==rb_red
X.parent.color=rb_black;
Y.color=rb_black;
X.parent.parent.color=rb_red;
X=X.parent.parent;
else
if X==X.parent.right
X=X.parent;
rb.tree=rb_rl(rb.tree,X);
end

X.parent.color=rb_black;
X.parent.parent.color=rb_red;
rb.tree=rb_rr(rb.tree,X.parent.parent);
end
else
Y=X.parent.parent.left;
if Y.color==rb_red
X.parent.color=rb_black;
Y.color=rb_black;
X.parent.parent.color=rb_red;
X=X.parent.parent;
else
if X==X.parent.left
X=X.parent;
rb.tree=rb_rr(rb.tree,X);
end
X.parent.color=rb_black;
X.parent.parent.color=rb_red;
rb.tree=rb_rl(rb.tree,X.parent.parent);
end
end
end
rb.tree.color=rb_black;

That is clearly low-level C like code.

Compare with the OCaml/F# (that supports persistence, garbage collection and
is much faster):

let rec ins x t = match t with
E -> R(E, x, E)
| R(a, y, b) ->
if x < y then R(ins x a, y, b) else
if x > y then R(a, y, ins x b) else t
| B(a, y, b) ->
if x < y then match ins x a, y, b with
| R(R(a, x, b), y, c), z, d -> R(B(a, x, b), y, B(c, z, d))
| R(a, x, R(b, y, c)), z, d -> R(B(a, x, b), y, B(c, z, d))
| a, x, b -> B(a, x, b) else
if x > y then match a, y, ins x b with
| a, x, R(R(b, y, c), z, d) -> R(B(a, x, b), y, B(c, z, d))
| a, x, R(b, y, R(c, z, d)) -> R(B(a, x, b), y, B(c, z, d))
| a, x, b -> B(a, x, b) else t

let add x s = match ins x s with
| R(a, y, b) -> B(a, y, b)
| s -> s

Common Lisp provides lists, trees and arrays. Its main problem is a
complete lack of static typing so programmers are unable to have even the
most basic constraints checked and productivity circles the drain as they
live in their debuggers trawling stack traces trying to find the original
of a simple type error.

I've never seriously tried Lisp. After playing with it a while, I got
drunk in thousands of ((())), polish notation and cdr, car which doesn't
make list processing easy.

I've toyed with Lisp as an academic curiosity but I would never try to write
any serious software in it because I learned as a child how dynamic typing
makes it practically impossible to write anything non-trivial correctly.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
.



Relevant Pages

  • Re: Wishlist for R2007b
    ... via escape sequences; those are about the closest you are ... Matlab always runs as a single process, ... inform Matlab that K:\ (windows) which has a 250 GB ... drive can be used for up to 50 GB of virtual memory. ...
    (comp.soft-sys.matlab)
  • Re: how to retain function variables in base works
    ... here is an estimate about matlab memory: ... For cell array, if you want to use it like a STL vector of JFC ... for an N element cell array, amount of memory ... it bad programming (even worse than global approach! ...
    (comp.soft-sys.matlab)
  • Re: Resizing a structur array in C
    ... I could find no MATLAB documentation that specifically discusses the ... indeed an array of mxArray *, each index corresponding to n fields (in ... memory onto the end of the array, so to speak, and the whole memory ... int newSizeOfArray1 ...
    (comp.soft-sys.matlab)
  • Re: NAS alternative to my junky Airport Extreme
    ... most European languages, won't it? ... memory moving their contents at once -- of 9 and other sizes. ... Hungarian and German both use umlauts. ... What accents do other languages put on the letter A? ...
    (uk.comp.sys.mac)
  • Re: Words on the heap
    ... Forth programs tend to be significantly smaller than equivalent functionality coded in other languages. ... The major reason is that it is optimized to encourage great modularity, so there is much higher code density. ... even on very memory-constrained platforms there is far less incentive to re-use dictionary space. ... On today's PC-type platforms, there is typically such a vast amount of memory available that, with Forth's natural memory conservation, it simply isn't sufficiently attractive to be able to discard portions of the dictionary. ...
    (comp.lang.forth)