[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
subroutines
From: 
John W. Eaton 
Subject: 
subroutines 
Date: 
Fri, 7 Aug 1998 01:56:25 0500 (CDT) 
On 6Aug1998, James A. Tzitzouris <address@hidden> wrote:
 This is a 2 part question. The first part may be a dumb question (i.e.,
 one answered in the man pages, though I can't find it).

 Is there support in octave 2.0.13 for subroutines? I know MATLAB 5.x has
 support for such things. By subroutine I mean something like the
 following (in MATLAB syntax, i.e., no need for "endfunction"):

 %%%%%%%%%%%%%%%% MATLAB 5.x Code norm.m %%%%%%%%%%%%%%%%%%%%%%%%%

 function val=norm(x)

 val = sqrt(sum(sq(x)));

 % now here is the definition of the subroutine sq()
 % which is only defined in the scope of norm()

 function y=sq(x)

 y = x.*x;
No, Octave doesn't currently handle multiple functions in a single
file in a way that is compatible with Matlab 5.x.
 Part 2: I am planning to write the qp() and nlp() functions for octave
 (they're on the wish list). The nlp() function will call the qp()
 function as a subroutine. Is it computationally faster to have a copy of
 the qp() function embedded in the nlp() code as a "subroutine" (assuming
 the answer to part 1 is "yes") or should I not waste my time with
 subroutines and just make an external call to qp() from nlp()?
Since a QP function would be useful by itself, it would seem to me
that it would make sense to define the QP and NLP functions so they
are both accessible.
There should be no significant performance penalty associated with
defining them in separate files.
jwe
 subroutines, James A. Tzitzouris, 1998/08/06
 subroutines,
John W. Eaton <=