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

6 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Nov. 2017
xtemp = num2cell(x0);
F(xtemp{:})

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by