Hi Roelof,

I gave a talk on J for engineers in my department, using Powerpoint for the talk and the J & MATLAB interpreters on a separate display for examples. By the way, I used 'mathematical notation as a tool of thought' for a title, because I really couldn't improve on Prof. Iverson's apt description.

As most of my colleagues use MATLAB, I did a small comparison using the calculation of a running average as a simple example. I chose that because a running average is one of the few simple things that engineers use that isn't already built into MATLAB as an executable command, and it's easy to explain.

I started with the mean =: +/%# definition of mean. After learning the glyphs, the algorithm is in the definition. In MATLAB you use mean(a) to take the mean, which hides the algorithm, but is kind of convenient (until you can't remember whether it is average(a) or mean(a) that you have to type). So what do you do if you have a 2-d matrix, 3-d matrix, 5-d matrix that you want the mean of? In MATLAB, finding the mean of a 5-d matrix involves typing mean(mean(mean(mean(a)))). Comparing this with mean^:5 a (or better still mean^:_ a for the general case) is illuminating.

For a running average, which is very handy for smoothing measured data, you might write something in J like rav =: +/\ % [ . Again, the algorithm is in the glyphs once you know what they mean.

Without looping explicitly, in MATLAB one might write something like

function [Vec] = runav(InVec,NAv)
z = [0 cumsum(x)]
Vec = ( z(NAv+1:length(InVec)+1) - z(1:length(InVec)-NAv+1) ) / Nav;


This uses the built-in cumulative sum function and an equivalence to compute the running average without looping. There is, incidentally a one-liner that can compute a running average in MATLAB, but that uses a trick that is even further from the algorithm. If there are any MATLAB users reading, I'd be interested in knowing if there is a loopless version that uses the obvious algorithm for a running average - I may have missed it. The point is that I've had to change the way I express the algorithm to get the language to do what I want without using an explicit loop.

Then, if I want to run my MATLAB running average on a 2+-dimensional vector it won't work as written, because cumsum needs another argument for arrays of more than one dimension. And even if I define cumsum in the multidimensional form, the catenation [ 0 cumsum(x,rank)] won't work because the 0 and cumulative sum now have different shapes. So I end up writing quite a different program to do the same thing in a higher dimension. The same J expression works for either case as written, because of the design of the language.

All the above doesn't mean J is 'better' than MATLAB in any meaningful general way. MATLAB does many things very well, sometimes in a more convenient way than J because it has so many 'built-in' features. The learning curve is also not so steep, particularly for people familiar with other procedural languages. I find J elegant and consistent, and that motivates me, but not everybody. If you want to know how your programs work and want to write general and efficient numerical code, J can be a good choice. If you want the answer to common problems without having to do a lot of work, MATLAB can be a good choice.

Just my opinion.

Sean





Brouwer, Roelof <[EMAIL PROTECTED]> wrote:
Are there links between Matlab and J? Is there a comparison made between
Matlab and J anywhere? It turns out that the people I want to introduce
J to know Matlab. Also I am often asked why I don't use Matlab rather
than J in my research.
Also how does one link to C? Again not for me but for others.

cheers
Roelof Roelof K. Brouwer PhD PEng
Temporary while visiting
Department of Mechanical Engineering
Stellenbosch University
PO Box X1
Matieland
7602
South Africa
land line 27 (0) 21 808 3606 cell 27 (0) 73 973 1858 skype roelofbrouwer
email [EMAIL PROTECTED]
www.tru.ca/advtech/compsci/faculty/rbrouwer
Permanent Contact information
Professor
Department of Computing Science
School of Advanced Technologies and Mathematics
Thompson Rivers University
900 McGill Road, PO Box 3010
Kamloops, BC, Canada,V2C 5N3
telephone numbers
1-250 828 5219 work
1-250-374-5874 home
1-250-377-6133 fax
home page www.tru.ca/advtech/compsci/faculty/rbrouwer
email [EMAIL PROTECTED]

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Randy MacDonald
Sent: September 22, 2006 8:49 PM
To: General forum
Subject: Re: [Jgeneral] I expect a table of ordered pairs for this

Roelof;

This sentence is of the form

   x ,/ x

which is the dyadic form of u/, which the Dictionary says means:

   x ,"_ _ x


------------------------------------------------------------------------
|\/| Randy A MacDonald   | APL: If you can say it, it's done.. (ram)
|/\| [EMAIL PROTECTED]  |
|\ | |If you cannot describe what you are doing BSc(Math) UNBF'83 |as a process, you don't know what you're doing. Sapere Aude | - W. E. Deming Natural Born APL'er | Demo website: http://156.34.75.56/
-----------------------------------------------------(INTP)----{ gnat }-

----- Original Message ----- From: "Roelof K. Brouwer" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, September 22, 2006 12:22 PM
Subject: [Jgeneral] I expect a table of ordered pairs for this


(i.3),/i.3 in J produces



0 1 2 0 1 2

How do you explain this

cheers



Roelof





Roelof K. Brouwer PhD PEng

Temporary while visiting

Department of Mechanical Engineering

Stellenbosch University

PO Box X1

Matieland

7602

South Africa



land line 27 (0) 21 808 3606

cell 27 (0) 73 973 1858
skype roelofbrouwer

email [EMAIL PROTECTED]

www.tru.ca/advtech/compsci/faculty/rbrouwer



Permanent Contact information

Professor

Department of Computing Science

School of Advanced Technologies and Mathematics

Thompson Rivers University

900 McGill Road, PO Box 3010

Kamloops, BC, Canada,V2C 5N3





telephone numbers

1-250 828 5219 work

1-250-374-5874 home

1-250-377-6133 fax

home page www.tru.ca/advtech/compsci/faculty/rbrouwer

email [EMAIL PROTECTED]



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm





--
Sean O'Byrne
Postdoctoral Fellow
School of Aerospace, Civil and Mechanical Engineering
University College, University of NSW
Australian Defence Force Academy
Northcott Drive, Canberra, ACT 2600, Australia
[EMAIL PROTECTED]
ph.  61-2-6268-8353
fax. 61-2-6268-8276
------------------------------------------------------

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to