필터 지우기
필터 지우기

How can I plot the gradient vector of y=f(X) which is perpendicular to the graph?

조회 수: 1 (최근 30일)
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)

채택된 답변

Seyyed Mohammad Saeed Damadi
Seyyed Mohammad Saeed Damadi 2018년 1월 11일
Axis equal cannot solve the problem. I solved it on my own. Here is the codes:
x=-pi:0.2:pi;
figure
y1=sin(x);
plot(x,y1,'linewidth',2)
xlim([-pi pi])
xlabel({'$x$'},'interpreter','latex')
ylabel({'$y$'},'interpreter','latex')
v1=-cos(x);
v2=ones(1,length(x));
hold on
quiver(x,y1,v1,v2,0.2)

추가 답변 (1개)

Kim Folmer Andersen
Kim Folmer Andersen 2018년 1월 11일
try; axis equal

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by