How to use gradient function for 3 variable in function?
Ältere Kommentare anzeigen
Hi, I have a nonlinear function such that myfunc(x(1), x(2), x(3), 5e6, 0, 're'). I want to evaluate the gradient of function at [x(1), x(2), x(3)]=[1.2, 1.5, 2.0]. I am trying to solve that problem by numerical gradient. Because myfunc consists of another functions and algorithms. How can I do this? Thanks.
Antworten (1)
Jan
am 1 Mai 2011
Use finite differences:
h = sqrt(eps(x));
y1 = myfunc(x(1)-h(1), x(2)-h(2), x(3)-h(3), 5e6, 0, 're');
y2 = myfunc(x(1)+h(1), x(2)+h(2), x(3)+h(3), 5e6, 0, 're');
yd = (y2 - y1) ./ (2 * h);
you can use an approximation of the 2nd derivative to improve the stepsize h.
Kategorien
Mehr zu Motor Drives finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!