help-octave
[Top][All Lists]
Advanced

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

Re: Question about oct files


From: Guillem Borrell Nogueras
Subject: Re: Question about oct files
Date: Sun, 28 May 2006 03:09:52 +0200
User-agent: KMail/1.9.1

On Sunday 28 May 2006 02:21, Keith Goodman wrote:
> On 5/27/06, Guillem Borrell Nogueras <address@hidden> wrote:
> > How can I make an oct file return a value allocated runtime? 
> > ColumnVector, Matrix... seem to allocate at compile time.
>
> I don't think I understand the question. But how about this:

You are right, the question was ambiguous. 

I am using the GSL ode integration routines, I need variable-step Runge-Kutta 
ode integration. This is an operation I do quite often and I was trying to 
wrap some of my code to use it with Octave.

Obviously I don't know how much time steps will be necessary to integrate the 
equation so I use a pointer and save the results incrementing it.  This is 
something that you cannot do in Fortran (well, something that I don't know 
how to do).

If I count the number of time steps and then I try to use the counter to 
create an octave Matrix...

*pointer=&pointer_top
int counter=1
while (t<t1)
        *pointer = rk_integration_routine(...)
        pointer++
        counter++

Matrix result(counter)
... then save the contents of pointer,pointer+1 ... to result.

I am trying something similar and I get a Segmentation Fault.  Is there a way 
to get the oct file to return the result of the integration?  The oct 
functions must return an octave_value and it seems that a Matrix, 
ColumnVector... cannot be allocated this way.

Or maybe I am doing something seriously wrong...

guillem

> >> abc(2,3,4)
>
> ans =
>
>   2  2  2  2
>   2  2  2  2
>   2  2  2  2
>
> where
>
> #include <oct.h>
> DEFUN_DLD(abc, args, nargout,"y = a*ones(b,c)")
> {
>   octave_value retval;
>   int a = args(0).int_value();
>   int b = args(1).int_value();
>   int c = args(2).int_value();
>  Matrix y(b,c,a);
>   return retval = y;
> 


-- 
Guillem Borrell Nogueras
WEBSITE
   http://torroja.dmt.upm.es:9673/Guillem_Site/
BLOG
   http://torroja.dmt.upm.es:9673/Guillem_Borrell/
EMAIL
   guillemborrell_at_gmail.com (personal)
   guillem_at_torroja.dmt.upm.es (CFD Lab. ETSIA)


reply via email to

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