help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arguments out?


From: Vic Norton
Subject: Re: Arguments out?
Date: Thu, 11 Dec 2003 18:05:36 -0500

Yeah, I thought about that later, Thorsten. Thanks for pointing it out.

So when you write something like

   function   [U, S, V] = svd(A)

and A comes in as an m x n, you might do the computations to get

   U - orthogonal m x m
   S - diagonal m x n
   V - orthogonal n x n

satisfying

   A = U * S * V'

Then you look at nargout.

You will only accept nargout = 0, 1, or 3. If nargout = 0 or 1, you want to return diag(S). If nargout = 3, you want to return the triple [U, S, V]. Apparently your final lines should read something like this

   if (nargout < 2)
      U = diag(S);
   elseif (nargout != 3)
      error("you don't know what you are doing, dummy!");
   endif

This is what bothers me. U and diag(S) are completely different kinds of objects. Writing U = diag(S) simply goes against my grain.


Regards,

Vic


At 6:10 PM +0100 12/11/03, Thorsten Meyer wrote:
Hi Vic,

try it like this:

function [a,b,c] = tete()
 if nargout == 0
   a = "zero";
 elseif nargout == 1
   a = "one";
 elseif nargout == 2
   a = "two";
   b = "one";
 elseif nargout == 3
   a = "three";
   b = "two";
   c = "one";
 end
endfunction

you'll get:
octave:9> tete
ans = null
octave:10> tete
ans = zero
octave:11> a=tete
a = one
octave:12> [a,b]=tete
a = two
b = one
octave:13> [d,e,f]=tete
d = three
e = two
f = one

Vic Norton wrote:

I'm afraid I don't understand how output arguments work in octave. I am writing a routine, simp, to solve the linear programming problem

   minimize
                 c * x
   subject to
               A * x = b
          prod( x(I) >= 0 ) == 1

The function should look like this

    [ x, pi, fail ] = simp( A, b, c, I )    #  pi * b == c * x

with nargout = 3. But, for nargout = 0, 1, 2, I would like it to return

    simp( A, b, c, I )                  #  nargout == 0, return ans = x
    x = simp( A, b, c, I )              #  nargout == 1
    [ x, fail ] = simp( A, b, c, I )    #  nargout == 2

Is this possible? Or do I have to use

    [ x, fail, pi ] = simp( A, b, c, I )

in order that the nargout = 0, 1, 2 returns be what I want?


Regards,

Vic




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]