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

5 ビュー (過去 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 Center および File ExchangeDevelop 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