fix parameters in function

조회 수: 16 (최근 30일)
John Miller
John Miller 2020년 9월 22일
댓글: Warren Boschen 2023년 1월 27일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by