Hi!
I am trying to optimize a vector. I want to find , where ()=0, and .
f_1 and f-2 are two procedural functions, stored in m-files (not straight-forward functions).
How can I do it with a viable (time-effective) algorithm?
Thanks!

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Mai 2022

0 Stimmen

Use fmincon. Make the objective f1^2 and use a nonlinear equality constraint with f2.

4 Kommentare

mahdi Izadi
mahdi Izadi am 25 Mai 2022
Thanks!
The problem is that f_1 returns a vector;
i.e. and matlab returns the error
Supplied objective function must return a scalar value. Indeed I am trying to solve n equations simulateneously and the sum of a function of answers should be one.
Could you please kindly let me know how can I fix this?
Thanks so much
Walter Roberson
Walter Roberson am 25 Mai 2022
norm(f1(a))
mahdi Izadi
mahdi Izadi am 25 Mai 2022
Dear Walter;
Thanks so much;
Your suggestion makes the work done;
However the algorithm is excrucietinly slow. (My vector has 100 of elements,) It takes 130 seconds roughly and the problem is that it is inside a loop that should work for more that 1000 iterations...
Is it possible to expedite this solver? I tried a better initial guess and it didn't work. I also tried different algorithms , SQP, iterative, ... but no improvement made in the speed.
Best regards
Mahdi
Walter Roberson
Walter Roberson am 25 Mai 2022
It depends what the calculations do. In particular, are there analytic forms of the jacobian? Possibly a sparse form? fmincon needs to estimate the gradient of every variable against every other variable, and if you have hundreds of variables that can get slow.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 24 Mai 2022
Bearbeitet: Matt J am 24 Mai 2022

0 Stimmen

You have two equations so, as long as numel(a)=2 and f1 and f2 are differentiable, you can use fsolve. If numel(a)>2 then you have more unknowns than equations and the problem is ill-posed.

1 Kommentar

mahdi Izadi
mahdi Izadi am 25 Mai 2022
Dear Matt;
Thanks;
I believe I explained a bit unclear. The problem is somehow OK, as I think the solution proposed above adressed this problem.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by