How can I plot the gradient vector of y=f(X) which is perpendicular to the graph?
1 回表示 (過去 30 日間)
古いコメントを表示
Seyyed Mohammad Saeed Damadi
2018 年 1 月 11 日
回答済み: Seyyed Mohammad Saeed Damadi
2018 年 1 月 11 日
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168692/image.jpeg)
To plot the gradient vectors of f(x)=y=sin(x), I plotted z=y-sin(x) contours and plotted the gradient vectors for each contour but I just want one curve which is equal y=sin(x) and its gradient vector. The codes I used are as follows:
x=-pi:0.2:pi;
y=-1:0.2:1;
[X,Y]=meshgrid(x,y);
Z=Y-sin(X);
contour(X,Y,Z)
xlabel({'$x$'},'interpreter','latex')
ylabel({'$y$'},'interpreter','latex')
[DX,DY] = gradient(Z,.2,.2);
hold on
quiver(X,Y,DX,DY,0.5)
0 件のコメント
採用された回答
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!