フィルターのクリア

How to get matlab to create a function from system inputs and perform its fminsearch

1 回表示 (過去 30 日間)
Nuttapong Sansuk
Nuttapong Sansuk 2018 年 3 月 2 日
回答済み: Tony Mohan Varghese 2018 年 3 月 21 日
I want to use the simplex search method 'fminsearch' https://de.mathworks.com/help/matlab/ref/fminsearch.html
to find the minimum point of a function for example f(x(1),x(2)) = x(2) - n*x(1) while n could be any number depending on the input of system.
There were 2 methods i tried implementing
1. create symbolic valuables
x = sym('x_%d',[1 2]);
syms n;
f = x(2) - n*x(1);
and then i got
f = x_2 - n*x_1
but i dont know how to convert it to
f = @(x,n)(x(2) - n*x(1));
so i can perform
n = %input;
fun = @(x)f(x,n);
x0 = [1,1];
x = fminsearch(fun,x0)
2. execute
x0 = [1,1];
x = fminsearch(@objectivefcn1,x0)
by creating an objective function
function f = objectivefcn1(x)
f = x(2) - n*x(1);
end
anyway, i still can't find a way to pass the input n to the function without doing
function f = objectivefcn1(x,n)
f = x(2) - n*x(1);
end

回答 (1 件)

Tony Mohan Varghese
Tony Mohan Varghese 2018 年 3 月 21 日
Please refer the example for minimizing a function with extra parameters:

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by