How to find the gradient of a parameter which is not direct solution of a function

1 次查看(过去 30 天)
Hi,
I have a system of 2D nonlilnear system (f(x,y)) where I use fsolve to solve them for x and y. Then x and y are used in least square sense to obtain some parameters (alpha). I need to find the gradient of the alpha, is there any way to find the finite difference this?
Thanks,
Syed
  5 个评论
J. Alex Lee
J. Alex Lee 2020-8-5
you actually want the gradient of the residual of the equation you want to find the zero for. in a least square minimizer, if the thing you are comparing against is constant (like data), it comes out to the gradient of your model with respect to the parameters. if you want to finite different approximation (sometimes it is the only thing you can do), you can simply evalute the residual (or model) at some small distance (in parameter space) away from your current iterate and literally take a finite difference approximation to the derivative.
if you need more specific help, you should post your actual equations and problem to be solved.
J. Alex Lee
J. Alex Lee 2020-8-5
Maybe it is my limitation, but this doesn't make much sense to me; I cannot understand the underlying math problem you are trying to solve.
Do you have 2 solvers going on (one is your fsolve, and you have some kind of outer optimizer)? If so, break up your problem into chunks. Your "gradient" question could have as well applied to the fsolve portion.

请先登录,再进行评论。

回答(1 个)

J. Alex Lee
J. Alex Lee 2020-8-5
Determining l1 for a "target Gam4" value appears not to be an optimization problem, but another root-finding problem. It seems that your gradient (Jacobian) in this case is necessarily numerical in nature.
In your posted plot, say you wanted to find l1 for the target value Gam4=1e4 (somewhere around l1~0.3), you can express the problem as the residual
Gam4_target = 1e4
l1 = fsolve(@(l1)resfun(l1,Gam4_target,parameters),0.3)
function res = resfun(l1,Gam4_target,parameters)
Gam4_iterate = SomeFunction(l1,parameters)
res = Gam4_target - Gam4_iterate;
end
where now you need a SomeFunction that computes Gam4 according to an input l1, which is presumably what you already have in the posted code - you just need to package it differently so you can run a rootfinder on the result.
Perhaps you can simply use fsolve on your "outer" root-finding problem. fsolve may or may not compute its own FD based gradient estimates, depending on what algorithm it uses and/or options supplied (sorry I do not have toolbox containing fsolve).

Community Treasure Hunt

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

Start Hunting!

Translated by