trying to use the fmincon function
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello,
I am trying to use the fmincon with a external function definition.
I ran the example at https://www.mathworks.com/help/optim/ug/fmincon.html and it wroked as described
I tried to define the function as an external function as shown below.
    % script calling fmincon start
        clc
        clear all
        x0=[-1,2];
        A=[1,2];
        b=1;
        zeta=fmincon(fun,x0,A,b);
    % script calling fmincon end
    % script defining fun start
    function q=fun(x)
    q=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
    end
    % script defining fun end
I get this error: Not renough input arguments from the fun  script
Not sure how to fix this probem
Thank you
0 件のコメント
採用された回答
  Torsten
      
      
 2022 年 6 月 22 日
         Works for me after changing "fun" in "@fun":
   % script calling fmincon start
        clc
        clear all
        x0=[-1,2];
        A=[1,2];
        b=1;
        zeta=fmincon(@fun,x0,A,b)
    % script calling fmincon end
    % script defining fun start
    function q=fun(x)
    q=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
    end
    % script defining fun end
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Surrogate Optimization についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

