how to use fmincon in a loop
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 5 unknown parameters but only 4 equations, but each parameter has an interval, so I prefer to use fmincon. For example, these are 4 equations:
2*x(3) + x(5) + 5*x(1) - 1=0;
x7*(4) + 3*x(3) + x(2) - 10=0;
x(3) + 2*x(5) + 5*x(1) - 3=0;
3*x(4) + 9*x(5) + x(2) - 10=0;
My idea is like this:
for x(1)=0.1:0.1:1
fmincon(@myfun, x0,[]...)
end
But I do not know how to let x(1) be changed in the loop.
Thank you for any suggestions in advance.
댓글 수: 4
Amit
2014년 2월 8일
3*x(4) + 9*x(6) + x(2) - 10=0;
is this correct? x(6)? I thought you had only 5 parameters?
채택된 답변
Amit
2014년 2월 8일
A = [5 0 2 0 1;
0 1 3 7 0;
5 0 1 0 2;
0 1 0 3 9];
b = [-1;-10;-3;-10];
FF = @(x) norm(A*x+b);
xx = fmincon(FF,rand(5,1),[],[],[],[],zeros(5,1),ones(5,1))
댓글 수: 5
Amit
2014년 2월 10일
what is i there?
In a way, lets say you're trying to vary x(5) only, you can do it two way.
- set the upper and lower bounds for x(5) as value-eps and value + eps, this will contain the value of x(5) within the range.
- For you objective function, use only 4 input variable and pass the value of x(5) as a scalar as in fmincon(@(x) myfun(x,x5val). In this scenario, you'll have to write the function accordingly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!