[Top][All Lists]

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

Re: standalone application (octave to c++): define anonymous function fo

From: mmuetzel
Subject: Re: standalone application (octave to c++): define anonymous function for nonlin_curvefit()
Date: Tue, 19 Feb 2019 05:41:51 -0600 (CST)

ola wrote
> Hi,
> I have one more question. 
> What if my function does not have a simple form (@(p,x) 1-exp(-p(1)*x)),
> but is calculated in the inner loop, as here:
> Matrix my_fun(Matrix& p, Matrix& x, Matrix& y, Matrix& z) {
>   octave_value_list out = octave::feval("zeros", ovl(y.rows(),
> x.cols()),1);
>   Matrix k(out(0).matrix_value());
>   for (unsigned int i = 0; i < x.cols(); ++i) {
>     for (unsigned int ii = 0; ii < y.rows(); ++ii) {
>       for (unsigned int iii = z(i,0); iii <= z(i,1); ++iii) {
>         k(ii, i) = k(ii, i) + (1-(exp( - p(iii-1) * x(0,i)))) *
> z(ii,iii-1);
>       }}} 
>   return k;       //here an error occure, when I call
> octave::feval("lsqcurvefit", ovl(my_fun(p,x,y,z), ...);
> }
> Is it correct if I use this function in this way?
> octave_value_list result = octave::feval("lsqcurvefit",
> ovl(my_fun(p,x,y,z), init, xdata, ydata, L, U, opt(0)), 6);

You have to pass a function handle of an Octave function when you call
"lsqcurvefit" from the interpreter. The Octave interpreter doesn't know
about your C++ function my_fun.
You could probably use .oct file functions if you want to write an Octave
function in C++. Please read e.g. "doc mkoctfile" or the Appendix A of the
manual for instructions.


Sent from:

reply via email to

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