How to use fmincon function arguments object in app designer?

Dear all,
This is my first posting in this community. So, hello community.
While there are many Q&As that helped me out in the past, I am now struggling to implement an object as function arguments for fmincon in the app designer (also first time I am using it).
The object function is declared public:
methods (Access = public)
function sumsquares = wlcobj(app,PLo,lobs,Fobs)
kbT = 4.1; % Room temperature 23.8°C
lcalc=force2wlc7(app,Fobs,PLo(1),kbT,PLo(2));
sumsquares=sum((lobs-lcalc).^2);
end
When I call it for the function input arguments:
x=fmincon('wlcobj',xo,[],[],[],[],xlb,xub,[],[],Extension,Force);
I get the error 'Undefined function 'wlcobj''.
I can certainly undertands that somewhat, since in the app designer one adds the 'app' information.
But I did not find any infor about how to do that.
Trying:
x=fmincon(app, @wlcobj,xo,[],[],[],[],xlb,xub,[],[],Extension,Force);
leads to the error ' Error using fmincon (line 225). FMINCON requires the following inputs to be of data type double: 'X0'.'.
So, that seems also to be the wrong syntax. In normal Matlab, it works... but in app designer not.
Anyone that could give me a tip how I can reference correxctly to the 'wlcobj' object for the function input arguments?
Thank you in advance!
Cheers,
Richard

Answers (1)

It's not clear from your post where the objective function is defined and where (in what workspace) you are invoking fmincon. When you say "wlcobj" is a public method, I will assume you mean it is a method of your app class. Also, it is not clear from your code which variables are the unknowns and which are fixed parameters. If I assume that PLo is your unknown vector, then your invocation of fmincon should look like,
x=fmincon(@(x)app.wlcobj(x, Extension, Force),xo,[],[],[],[],xlb,xub);
Note, however, that lsqcurvefit or lsqnonlin would be more apt for your problem, since they are specially designed for nonlinear least squares optimization problems.
See also,

3 Comments

Richard Janissen replied:
Hi Matt,
Thank you for your prompt reply.
You made me think about something that I should look closer at.
I'l come back to you.
Cheers,
Richard
Hi Matt,
I have the same question and your answer helped me.
Thanks alot
@mojtaba rayati I'm happy it helped, but please Accept-click the answer to indicate so.

Sign in to comment.

Products

Asked:

on 27 Aug 2020

Commented:

on 27 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!