Problem with Minimizing a Function of Several Variables
이전 댓글 표시
Hi there, I want to find a minimum for this function:
g = 0.04 - (32*P/(9*sqrt(3)*E*MOI));
and I've written this code to do so:
clc;
clear;
function b = three_var(v)
P = v(1);
E = v(2);
MOI = v(3);
b = 0.04 - (32*P/(9*sqrt(3)*E*MOI));
end;
v = [0.12 -2.0 -0.35];
a = fminsearch(@three_var,v)
but I get the error "Function definitions are not permitted in this context". I've been stuck with this for a day and don't know what to do. I would be grateful if you could help.
채택된 답변
추가 답변 (2개)
John D'Errico
2015년 11월 9일
3 개 추천
As both Matt and Star have pointed out, you need to define the function properly to use a solver like fminsearch, but they have shown you how to do so.
More importantly, on this particular problem, there is NO solution. You can choose sets of values that will yield arbitrarily large negative values, as close to -inf as you wish to go. The minimization problem will be divergent for this objective function.
You cannot define functions (like three_var) inside a script. Make your mfile a function file.
카테고리
도움말 센터 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!