How can I plot arrows over a function? (For ODE solution)

조회 수: 3 (최근 30일)
Oscar Ramos Soto
Oscar Ramos Soto 2019년 6월 14일
답변: Star Strider 2019년 6월 14일
Hi! I want to plot arrows over a function , for example if I have a Sin(x) function, plot the arrows and its directions.
Maybe I'm not clear, so I'll let an example down here.
I've tried using quiver() but I cant get the results as the image below.
Thanks a lot.Captura de pantalla (843).png

채택된 답변

Star Strider
Star Strider 2019년 6월 14일
Try this:
t = linspace(0, 2, 25);
h = t(2)-t(1);
s = sin(2*pi*t/max(t));
ds = gradient(s,h);
dt = gradient(t,h);
figure
quiver(t,s, dt,ds)
grid
producing:
How can I plot arrows over a function (For ODE solution) - 2019 06 13.png
This calculates the derivative from the data (here sin(t)). You may be able to recover your derivative directly from your ODE, so you may not need to calculate the gradient of your solved vector. I will leave that for you to determine.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by