I want to optimize one parameter of a function with three parameters. Lets say the function looks like this
function f = function(t,x)
f = x(1) + x(2) *x(3)
end
How can I transmit the values for x(1) and x(2) but leave x(3) open to a later optimization?

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 22 日

0 投票

Yes, you can only optimize using selected variables. For example, following use x(3) for optimization, while x(1) and x(2) are fixed.
x1 = 2; % write value of x(1)
x2 = 3; % write value of x(2)
t = 0; % write value of t
x30 = rand(); % initial guess for x3
sol = fmincon(@(x3) myFunction(t, [x1; x2; x3]), x30)
function f = myFunction(t,x)
f = x(1) + x(2) *x(3)
end

3 件のコメント

Warren Boschen
Warren Boschen 2023 年 1 月 27 日
So if I wanted to write an expression where I fit two variables x and y while holding two other parameters data1 and data2 constant, would it read like this? Note that data1 and data2 are column vectors and x and y are scalars.
sol = fmincon(@(x,y) myFunction(data1, data2, x, y), [x0, y0]);
Thanks,
Warren
Torsten
Torsten 2023 年 1 月 27 日
sol = fmincon(@(x) myFunction(data1, data2, x(1), x(2)), [x0, y0]);
Warren Boschen
Warren Boschen 2023 年 1 月 27 日
Ah okay. Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Design Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by