필터 지우기
필터 지우기

Use of the optimisation toolbox,

조회 수: 1 (최근 30일)
james
james 2012년 3월 16일
I have the code to display 2 functions in a graphical form I need to find the minimum point with several constraints, my code to display the equations is
x = 0.1:.01:2.1;
y = 0:.05:10;
[X,Y] = meshgrid(x,y);
Z = meshgrid(0.125:.025:5.125);
C = (1.10471.*((Z).^2) .* ((X).^2))+(0.0481.*(Y.*Z)*14.*X);
surfc(X,Y,Z,C);
axis([0 2.1 0 10 0 5.125]);
hold on;
R = 6000./sqrt(2.*Z.*X);
A = 6000*(14+0.5*X)*sqrt(0.25*(X).^2 +(Z+Y).^2);
B= 2*0.707*Z.*X.*(((X).^2)/(12+0.25*(Z+Y)^2));
S =A./B;
T=sqrt((((R).^2)+((S).^2)+X.*R.*S)./sqrt(0.25*((X).^2)+(Z+Y).^2));
surfc(X,Y,Z,T);
I'm trying to now use the function fminunc to minimalise the term for C whereby T is less than 13600 so far I thought it best to do firstly minimise the innital equation before inputing the futher constraints so my code is as follows,
function f = myfun(x)
f = (1.10471*(x(1)^2) * (x(1)^2))+(0.0481*(x(2)*x(3))*14*x(1));
x0 = [1,1];
[x,fval] = fminunc(@myfun,x0);
however when run this returns the statement
??? Input argument "x" is undefined.
Error in ==> myfun at 2
f = (1.10471*(x(1)^2) * (x(1)^2))+(0.0481*(x(2)*x(3))*14*x(1));
>>
Any clues as to where I'm going wrong?
Many thanks

답변 (2개)

Walter Roberson
Walter Roberson 2012년 3월 16일
Split your code like
function [x, fval] = minimize_myfun
x0 = [1,1];
[x,fval] = fminunc(@myfun,x0);
function f = myfun(x)
f = (1.10471*(x(1)^2) * (x(1)^2))+(0.0481*(x(2)*x(3))*14*x(1));
It is important that you do not have the call to fminunc within the myfun function.

james
james 2012년 3월 16일
ok that makes sense thanks for that, I'm now getting an error whereby it thinks there are too many input arguments? is that because my code would call upon x(3)? Also would I just put the constraints into the bottom of the code?
Sorry for my lack of coding knowledge
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 3월 16일
Your x0 does need to be as long as the maximum subscript of x that you reference.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by