help-octave
[Top][All Lists]
Advanced

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

Re: diag octave command into cc file


From: Michael Creel
Subject: Re: diag octave command into cc file
Date: Tue, 03 Oct 2006 15:57:56 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060922)

Riccardo Corradini wrote:
I would like to use command diag into cc
Is there a simple instruction like DiagMatrix to indicate the vector and the exact diagonal?
How is possible to do for oct files?
Thanks a lot in advance

Hi Riccardo,
I saw your message on the PK forum, but I'm answering here since the question is octave-related. The code
-------------------------
#include <oct.h>
#include <octave/parse.h>
DEFUN_DLD(KalmanInn_trans, args, ,"KalmanInn_trans.cc: C++ version for increased speed")
{
        octave_value_list f_args, f_return;
        
        // extract the arguments
        ColumnVector parameter = args(0).column_vector_value();
        int which_diagonal = args(1).int_value();
        f_args(1) = which_diagonal;
        f_args(0) = parameter;

        f_return(0)=feval("diag", f_args);

        return f_return;
}
---------------------------------------
does what you need, I think. The output is:

Welcome to MPITB
octave:1> a = rand(3,1)
a =

  0.87025
  0.67221
  0.89550

octave:2> KalmanInn_trans(a,2)
ans =
(
  [1] =

    0.00000  0.00000  0.87025  0.00000  0.00000
    0.00000  0.00000  0.00000  0.67221  0.00000
    0.00000  0.00000  0.00000  0.00000  0.89550
    0.00000  0.00000  0.00000  0.00000  0.00000
    0.00000  0.00000  0.00000  0.00000  0.00000

)
octave:3>


This is an example of how to call an Octave function from an .oct function. There's no speedup in the way the matrix is created, though, the "diag" code is the same as if it were called directly from the interpreter.

Cheers, Michael



reply via email to

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