How to get matlab to create a function from system inputs and perform its fminsearch
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Tony Mohan Varghese
2018-3-21
Please refer the example for minimizing a function with extra parameters:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!