Finding close-to-linear solution
Mostrar comentarios más antiguos
I am using fsolve within fsolve. The most time spent in my code is on the inner fsolve function which matlab calls 1.5 million times.
The inner function that needs to be solved is as follows:
function F = solveE(E,c)
F = E - log(c'*exp(0.99*E));
Here, E is an Nx1 vector and c is an NxN matrix. N is typically around 400. Values for c are all positive and real. Values for E are negative and real. Is there a faster way of solving this?
Within the outer fsolve, I call this function using
E0 = fsolve(@(E) solveE(E,c),E0,options);
One thing I am already doing is to use my solution E0 as an initial guess for the next iteration (when matlab adjusts its guess for the variable that solves the outer fsolve, which then will change the value for c).
Thanks for any suggestions.
Respuesta aceptada
Más respuestas (1)
Using fsolve inside of fsolve is a doubtful-sounding thing to do. Why not just combine the equations from solveE with the equations in your outer problem and solve a single system?
As a simpler example, instead of having something like this as your equation function...
function F=Equations(x,z0)
z=fsolve(@(z) z^3-x, z0);
F(1)=x+1-z;
end
...it is probably better to have this
function F=Equations(xz)
x=xz(1); z=xz(2);
F(1)=z^3-x;
F(2)=x+1-z;
end
5 comentarios
Yes, indeed. The first formulation is equivalent to,
function F=Equations(x,z0)
F=x+1-x.^(1/3);
end
which is non-differentiableat x=0, thus violating the differntiability assumptions of fsolve. I speculate that it wouldn't cause too much trouble in this instance, though, since the solver is unlikely to stray too close to x=0 as long as your initial guess is decently well-informed
Tintin Milou
el 17 de Mayo de 2022
whereas the inner fsolve is quite quick.
In what way? Your original post says that that's where most of the time is spent.
I think my function is well behaved. So non-differentiability is unlikely to be a concern.
How do you know that?
Tintin Milou
el 17 de Mayo de 2022
I don't know what "well-behaved" refers to here. It seems very hard to know in advance whether the result of the inner fsolve will be differentiable with respect to the outer unknowns. It certainly isn't guaranteed by the smoothness of solveE. You can see in Catalytic's example that the inner equation function @(z) z^3-x is a highly smooth, polynomial function of both z and x. Yet, solving for z leads to a non-differentiable function of x.
Categorías
Más información sobre Quadratic Programming and Cone Programming 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!