running function in the command line

3 ビュー (過去 30 日間)
ARUN BORGOHAIN
ARUN BORGOHAIN 2017 年 6 月 17 日
編集済み: ARUN BORGOHAIN 2017 年 6 月 20 日
I am interested to run optimization (lsqnonlin) in the command line itself without calling or creating a ☆.m file!
clc; clear all
k = 1:10;
fun =@(x) ( 2 + 2*k-exp(k*x(1))-exp(k*x(2)) );
% Next, invoke an optimization routine.
x0 = [0.3 0.4] % Starting guess
[x,resnorm] = lsqnonlin ( fun, x0 );
  2 件のコメント
dpb
dpb 2017 年 6 月 17 日
What's the question? Works here...
>> [x,resnorm]=lsqnonlin(fun,x0)
Local minimum possible.
lsqnonlin stopped because the size of the current step is less than
the default value of the step size tolerance.
<stopping criteria details>
x =
0.2578 0.2578
resnorm =
124.3622
>>
which is same result as the example using the function m-file in the doc.
ARUN BORGOHAIN
ARUN BORGOHAIN 2017 年 6 月 18 日
編集済み: ARUN BORGOHAIN 2017 年 6 月 20 日
How to add options is my problem (sorry left that part in pasting)!
options = optimset('Display','iter','TolX',1e-3);
[x,resnorm] = lsqnonlin ( fun, options, x0 );
%Error using lsqnonlin (line 181);LSQNONLIN only % accepts inputs of data type double.

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 18 日
[x,resnorm] = lsqnonlin( fun, x0, [], [], options );
Parameters are positional. options must appear in the 5th parameter.
  1 件のコメント
ARUN BORGOHAIN
ARUN BORGOHAIN 2017 年 6 月 18 日
thanks!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by