function F = TEST6lijn300(x, p)
F = [(x(1)^2 + x(2)^2 - p(1));
((1447.5-x(3))^2 + (876.3-x(4))^2-p(2));
((-72.4-x(5))^2 + (1723.1-x(6))^2-p(3));
(x(5)^2 - 2*(x(5)*x(1)) + x(1)^2 + x(6)^2 - 2*(x(6)*x(2)) + x(2)^2 - 20449);
(x(3)^2 - 2*(x(3)*x(1)) + x(1)^2 + x(4)^2 - 2*(x(4)*x(2)) + x(2)^2 - 20449);
(x(3)^2 - 2*(x(3)*x(5)) + x(5)^2 + x(4)^2 - 2*(x(4)*x(6)) + x(6)^2 - 20449)];
end
The call would be
...
p = [753233.1, 966977.2, 957129.6] ;
[x,fval] = fsolve(@(x)TEST6lijn300(x,p),x0,options) ;
EDIT2: if all your sets of p values are in an Excel file, you can do the following (that you could make more concise by eliminating temporary variables):
x0 = ...
options = ...
filename = 'myFile.xlsx' ;
sheet = 'mySheet' ;
P = xlsread(filename, sheet) ;
n = size(P, 1) ;
X = zeros(n, length(x0)) ;
for ii = 1 : n
fh = @(x) TEST6lijn300(x, P(ii,:)) ;
X(ii,:) = fsolve(fh, x0, options) ;
end
Note: fh is a function handle on an anonymous function that takes 1 input parameter, x, and calls your function TEST6lijn300 with the two arguments that it requires, here x and ii-th row of P that is the ii-th set of p values. Jan's comment refers to a post explaining that using an anonymous function is the proper way to manage this type of situations where you have to match interfaces between your function and some solver requirements.
Cedric
Best Answer