Error while applying fminunc : fun must be a function

1 回表示 (過去 30 日間)
Tushar Shinde
Tushar Shinde 2017 年 1 月 31 日
回答済み: Walter Roberson 2017 年 1 月 31 日
Hi, I have just started learning and using matlab functions. I wanted to minimize simple quadratic function as follows:
fun = x.^2
x0 = 10
[x, fval] = fminunc(fun, x0)
I was expecting o/p as x=0 fval=0 but instead it gave me: fun should be a function or string or inline....
It is such a simple script. Where am I going wrong?
Thanx in advance :)

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 31 日
fun = @(x) x.^2

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by