Fmincon creates complex input vector
이전 댓글 표시
Some might remember me from some earlier questions. I have programmed an aircraft generator and analyzer. I'm trying to find an optimized aircraft, but after several months still no luck. Yesterday I started an optimization, which ran for about 12 hours and did 27 iteration successfully. I finally thought it was going to work, yet, halfway through the 28th iteration it failed again.
This time my objective function failed, so normally this is a fault in my own program. It returned an error that one of the variables had an imaginary part, which shouldn't be possible. After loading the currentxvector, which I save to debug problems like this, I quickly discovered that all of the values of the input vector (xvector as it is called in my program) are complex. How is this possible? I thought fmincon is not able to work with complex numbers. Did it make and error, or did I?
Needless to say that my start xvector has only real numbers and all of the preceding 27 iterations had only real numbers as well. I have no clue where this comes from and how to handle this problem. My xvector has a length of 31. I use an active-line algorithm now, that seemed to work fine until this came along.
I hope someone can help me out. I apologize for the number of questions asked. It is really a complex problem, which I hope to solve soon.
My xvector is saved as soon as the objective function is started, so I don't alter anything. If I'm right this is just the xvector created by fmincon. The way my xvector is saved:
function f = obj(aircraftstart,x)
%Save current xvector, for debugging purposes
eval(sprintf('%s%s%s','save(''optdata\',problem.TAG,...
'\currentxvector.mat'',''x'')'))
<Calculations>
return
채택된 답변
추가 답변 (1개)
Max
2011년 7월 21일
0 개 추천
Does your objective function contain logs or non-integer powers of variables that take negative values in a neighbourhood containing your initial guess and the nearest local optimum? Taking logs or non-integer powers of negative numbers will land you with complex numbers. I often run into this problem after calculating what are supposed to be very small positive numbers which are actually returned as negative values due to numerical error. I can usually fix the problem by explicitly ensuring all values are positive before being passed to a log (or other function) that requires positive inputs in order to return real outputs; this usually involves setting negative values equal to eps or an otherwise small positive real.
카테고리
도움말 센터 및 File Exchange에서 Choose a Solver에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!