Calculate the Gradient of a given function using the forward and central quotients.

1 回表示 (過去 30 日間)
kai kai
kai kai 2021 年 1 月 13 日
コメント済み: kai kai 2021 年 1 月 13 日
I am very bad at this, it would be hard for me to calculate it even for only one variable, but now that I have to calculate the Gradient i am completely lost.
Please help me out, any sort of help is very much appreciated.
My failed code:
function f1x = vordiff(f,x,h,y,z)
%Vorwärtsdifferenzenquotienten
function f = f(x,y,z)
f = (4*x+3*y+2*z)*e^(-3*x^2)-4*y^2-8*x*y-2*z^2
end
f1x = (f(x+h)-f(x))/h;
f1z = (f(z+h)-f(z))/h;
f1y = (f(y+h)-f(y))/h;
end

回答 (1 件)

KSSV
KSSV 2021 年 1 月 13 日
function f1x = vordiff(f,x,h,y,z)
%Vorwärtsdifferenzenquotienten
syms x y z ;
f = (4*x+3*y+2*z)*e^(-3*x^2)-4*y^2-8*x*y-2*z^2
fx = diff(f,x) ;
fy = diff(f,y) ;
fz = diff(f,z) ;
end
  4 件のコメント
kai kai
kai kai 2021 年 1 月 13 日
Thank you so so much you saved me. Very helpful. I don't know if you can put it as an answer so that I can vote it as best answer.
kai kai
kai kai 2021 年 1 月 13 日
And the results were exactly the same, I don't know if this is how it is supposed to be.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by