How to use gradient function for 3 variable in function?

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.

回答 (1 件)

Jan
Jan 2011 年 5 月 1 日

1 投票

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.

カテゴリ

ヘルプ センター および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

質問済み:

2011 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by