using fsolve in a shared c++ lib, problem of function handle

  • Follow


Hello,

I'm trying to use fsolve in a shared c++ library created by Matlab (7.10.0.499 32 bits) for Visual Studio 2008 SP1 (with the deploy tool). 

I can use lsqlin without any problem, but it seems to be more painful when using function handles ...

I wrote a .m file with the following function :

function y = matlab_solve(arg1, arg2, arg3)
     fhandle = getHandleFunc(arg1, arg2, arg3);
     
     function fhandle = getHandleFunc(a1, a2, a3)
          function F = func(x)
               F = ... (using a1, a2 and a3);
          end

          fhandle = @func;
     end
     
     x0 = ...;
     y = fsolve(fhandle, x0);
end

I wrote these nested functions as I need to create a function F depending on the inputs arg1, arg2 etc.

However, when using the function matlab_solve in my C++ program, I got the error : 
??? Undefined function of method 'lsqfcnchk' fo input arguments of type 'function_handle'.

So two questions come to my mind :
     - can I use a nested function for fsolve ?
     - if I have some inputs for the general function matlab_solve, can I use them inside the definition of the nested functions ?

Looking forward to hear some comments,
Thanks,
Benoit
0
Reply Benoit 10/12/2010 6:43:04 PM

Instead of creating function handle, just concatenate the arguments, pass these arguments as string. The concatenated argument can then go as a inline function input to fsolve.

 "Benoit Brot" wrote in message <i92a7o$b6v$1@fred.mathworks.com>...
> Hello,
> 
> I'm trying to use fsolve in a shared c++ library created by Matlab (7.10.0.499 32 bits) for Visual Studio 2008 SP1 (with the deploy tool). 
> 
> I can use lsqlin without any problem, but it seems to be more painful when using function handles ...
> 
> I wrote a .m file with the following function :
> 
> function y = matlab_solve(arg1, arg2, arg3)
>      fhandle = getHandleFunc(arg1, arg2, arg3);
>      
>      function fhandle = getHandleFunc(a1, a2, a3)
>           function F = func(x)
>                F = ... (using a1, a2 and a3);
>           end
> 
>           fhandle = @func;
>      end
>      
>      x0 = ...;
>      y = fsolve(fhandle, x0);
> end
> 
> I wrote these nested functions as I need to create a function F depending on the inputs arg1, arg2 etc.
> 
> However, when using the function matlab_solve in my C++ program, I got the error : 
> ??? Undefined function of method 'lsqfcnchk' fo input arguments of type 'function_handle'.
> 
> So two questions come to my mind :
>      - can I use a nested function for fsolve ?
>      - if I have some inputs for the general function matlab_solve, can I use them inside the definition of the nested functions ?
> 
> Looking forward to hear some comments,
> Thanks,
> Benoit
0
Reply ddmandaliya (1) 5/3/2012 6:38:07 PM


1 Replies
312 Views

(page loaded in 0.117 seconds)

Similiar Articles:













7/30/2012 8:07:27 PM


Reply: