How to input a vector into a multi variable function as individual components?

4 次查看(过去 30 天)
This top part will be the input of my function and this part cannot be manipulated.
F = @(x1,x2) [(4*x1^2 - 20*x1 + x2^2/4 + 8) ; (x1*x2/2 + 2*x1 - 5*x2 + 8)];
x0 = [0 ; 0];
What I want to do is evaluate the function at F(x0(1),x0(2)) (for this example) and have it output the solution. But to keep it general let's say
i = nargin(F)
for n = 1:i
F(x0(1),x0(2),x0(...),x0(n))
end
not real and it's definitely ghetto code but hopefully shows you what I'd like to do. I'm looking for a way to evaluate F composed of the individual components of x0 basically.
Also, x0 will always be a column vector with the length equal to the number of inputs in F.
The solution for what I want in the above example is: F(0,0) = [8 ; 8]
Hopefully this makes sense... Any advice would be greatly appreciated!

采纳的回答

Walter Roberson
Walter Roberson 2017-11-28
xtemp = num2cell(x0);
F(xtemp{:})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by