Passing xtra parameter

8 ビュー (過去 30 日間)
srycandy
srycandy 2012 年 2 月 24 日
編集済み: W. Owen Brimijoin 2013 年 10 月 23 日
i do an example provide in matlab on passing xtra parameter. these are the codes:
function y = parameterfun(x,a,b,c)
a = 4; b = 2.1; c = 4; % Assign parameter values
x0 = [0.5,0.5];
y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) +(-c + c*x(2)^2)*x(2)^2;
f = @(x)parameterfun(x,a,b,c);
[x,fval] = fminunc(f,x0)
end
However, i got an error said that:
??? Input argument "x" is undefined.
Error in ==> parameterfun at 4
y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) +(-c + c*x(2)^2)*x(2)^2;
please help me. I dont know how to fix it. tq

回答 (1 件)

Geoff
Geoff 2012 年 2 月 24 日
That doesn't look right. I am guessing you intended to do the following:
function y = parameterfun(x,a,b,c)
y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) +(-c + c*x(2)^2)*x(2)^2;
end
a = 4; b = 2.1; c = 4; % Assign parameter values
x0 = [0.5,0.5];
f = @(x)parameterfun(x,a,b,c);
[x,fval] = fminunc(f,x0)
  2 件のコメント
srycandy
srycandy 2012 年 2 月 24 日
I get this error, when i use ur suggestion.
??? Error: File: parameterfun.m Line: 5 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function
"parameterfun".)
srycandy
srycandy 2012 年 2 月 24 日
i already get the answer... silly me.. starting line 4 to last line , we have to run it at command prompt.. why it has to be like that?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by