Same functionality as Excel Solver to set objective to a value
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi all
I am currently going through a process of taking an existing calculation perfomed within Excel and transferring it to MATLAB. Part of the existing calculation is to use Excel Solver to optimise two factors to allow a value to be calculated which matches a target value. This was achieved in the Excel solver by setting the objective to a fixed value using the 'Value Of' input box.
Going through the MATLAB optimisation functions I can only find solutions to minimise the value. My question is what function would I use to target a value? Note that I do not have the optimisation toolbox installed.
Many Thanks
Peter
댓글 수: 0
채택된 답변
Alan Weiss
2012년 6월 7일
I am not sure I understand your question. If you have a single function of a single variable, you can use fzero to solve for f(x) = a, by solving for a zero of the function f(x) - a.
However, you seem to have a single function of two variables, or perhaps you have two functions of two variables. If you have two functions of two variables, use fsolve to find a solution. If you have a single function of two variables, I don't understand what you or Excel can do to find a solution, because in general there are multiple solutions.
And I do not recommend using abs in Optimization Toolbox functions, this introduces unnecessary nonsmoothness. Use a square if you need to (but you probably do not need to).
Alan Weiss
MATLAB mathematical toolbox documentation
추가 답변 (1개)
Titus Edelhofer
2012년 6월 7일
Hi Peter,
to optimize a variable to be of value XTarget, you need to minimize the function
abs(x - XTarget)
If you don't have restrictions, you can use fminsearch as solver.
Titus
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!