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!