Using fsolve with array of symbolic expressions
Mostrar comentarios más antiguos
Hi there,
I have a vector of symbolic expressions, say for example
c = sym('c', [1 2]);
eqn=[c(1)^2-c(2), c(1)^3+c(2)^2];
and I want to use it to solve the nonlinear system of equations: eqn==0. (of course for this specific easy example I gave you, there are other ways to solve it, but none of them would work for a large eqn, which must be created independently of the solver and is really expensive to be created).
My initial method was to convert the expressions to a function handle:
eqn=matlabFunction(eqn)
and then solve it:
options = optimset('Display', 'off');
X = fsolve(eqn, ones(1, 2), options);
but it doesn't work, since fsolve accepts functions with one argument (which can be a vector) but matlabFunction gives me something like @(c1,c2)[-c2+c1.^2,c1.^3+c2.^2]. Do you have a recommendation?
Limitations:
1) eqn MUST be a symbolic vector and it MUST be created independently of the nonlinear solver, so solutions like
@c [c(1)^2-c(2), c(1)^3+c(2)^2]
or calling a function that creates the symbolic vector at each trial wouldn't be helpful.
2) We can't use the subs function to substitute the variables in each trial of the solver, because this takes ages.
I would really appreciate any answer.
Thanks!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!