MATLAB: Function as sum of functions in fsolve

factors as arraysfsolveMATLABOptimization Toolbox

I want to solve a set of nonlinear equations over two unknowns x(1) & x(2), e.g. in the form:
where factors a(i), b(i), k(j) and m(j) are known. I am not aware of how I can define the function: fun= @ (x) in a loop. Some help here would be really appreciated! Saeid

Best Answer

Just like you would without a loop. I assume you mean a loop over j...
asum=sum(a);
bsum=sum(b);
for j=1:length(k)
fun=@(x) myfun(x,asum,bsum,m(j),k(j));
xsol(j)=fsolve(fun,...)
end
function F=myfun(x, asum,bsum, mj,kj)
x1=x(1); x2=x(2);
F=[asum*x1^2+bsum*x1*x2^2 - kj ; you_fill_in_the_rest]
end