Optimizaation problem in matlab

2 views (last 30 days)
Hi,
I have a function in matlab which is dependent on four variable ( x1,x2,x3 and x4). I want to optimize the function output in matlab. I have access to optimization toolbox but i dont know anything about it.
For my fucntion i cant write function model because output of the function is a complex calculation invoving 100 lines of code.Basically i want to optimize a function output, depending on the four variable within given limits.
Anybody knows how i can proceed ?

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 4 Jan 2012
Hi Sukuchha,
it doesn't matter how complex your function is or how many lines it has. What you need to do is (conceptually) simple: write a function (with as many lines of code as you like) that has the following structure:
function y = myfun(x)
% x is the vector of unknowns, if you like you could write:
x1 = x(1);
x2 = x(2);
x3 = x(3);
x4 = x(4);
% now come the many lines to compute what ever you want to have
% optimized, i.e., some lengthy computations leading to some y
% where the final y you are looking for fulfills
% |y(xFinal)| = minimum of all x
y = ...;
Then think of bounds for x and call
x0 = [1;1;1;1]; % or some better starting point
lb = [1 2 3 4]; % the lower bounds for your parameters
ub = [5 6 7 8]; % the upper bounds for your parameters
xOpt = fmincon(@myfun, x0, [], [], [], [], lb, ub);
Titus
  1 Comment
Sukuchha
Sukuchha on 4 Jan 2012
thanks Titus, you been a saviour to me :)

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!