Function as sum of functions in fsolve

1 visualización (últimos 30 días)
Saeid
Saeid el 23 de Mzo. de 2017
Comentada: Walter Roberson el 23 de Mzo. de 2017
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

Respuesta aceptada

Matt J
Matt J el 23 de Mzo. de 2017
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
  1 comentario
Walter Roberson
Walter Roberson el 23 de Mzo. de 2017
I like the optimization of moving the asum and bsum out of the loop.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by