フィルターのクリア

Trying to do a animation of tangent line and secant line for my calc class.

4 ビュー (過去 30 日間)
Bruce Griffin
Bruce Griffin 2022 年 10 月 25 日
My calculus class is doing mean value theroem. I want to code something to graph a function and a secant line at two given points [a,b]
I then wanted to animate tangent lines starting from a and going to b.
my issue is that I cant think this through and remember how to code for a given value.
I was thinking of something like:
x=linspace(-10,10)
y=function of x
m=diff(y)
then creating a loop. but I cant think of how to tell the loop when x value at which loop to graph the line from
  1 件のコメント
Alex Hanes
Alex Hanes 2022 年 10 月 26 日
編集済み: Alex Hanes 2022 年 10 月 26 日
First off, I suggest that you take a look at MATLAB's On Ramp to gain some familiarity with what you can do and how you can do them in MATLAB.
If you intend to use the numerical result of y = f(x) rather than symbolic, then it would be easiest to define your function:
a = -10;
b = +10;
x = linspace(a,b,256); % domain of x
y1 = sin(x); % function
Then define your derivative with the exact function (e.g., not using diff):
y2 = cos(x); % derivative of y1
To plot the secant, you can just evaluate your function at the end points:
figure(1); clf; hold on;
plot(y1(a),y1(b),'k-','LineWidth',2); % Plot Secant Line
To plot the derivative at each x-value, you should look at the documentation forfor loops.

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

回答 (2 件)

Carlos Guerrero García
Carlos Guerrero García 2022 年 11 月 7 日
編集済み: DGM 2022 年 11 月 14 日
I hope that this script is that you're looking for:
x=-1:0.01:6; s=[-2 2];
for u=-pi/2:pi/360:4*pi;
t=3+2*sin(u);
plot(x,2+((x-1)/2).^2,[-0.5 6],[0.5 7],[0 0],[-2 8],'k',[-2 8],[0 0],'k');
hold on;
plot(t+s*2/sqrt(4+(t-1)^2),2+((t-1)/2)^2+s*(t-1)/sqrt(4+(t-1)^2),'k');
plot(t,2+((t-1)/2)^2,'.k','MarkerSize',20);
axis equal; axis off;
drawnow;
hold off;
end
  3 件のコメント
DGM
DGM 2022 年 11 月 14 日
Glad to hear some earnest motivation! I worry sometimes that I might discourage new users with little suggestive edits like that.
Welcome to the forum :D
Carlos Guerrero García
Carlos Guerrero García 2022 年 11 月 14 日
Thanks DGM for your welcome!!!

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


Carlos Guerrero García
Carlos Guerrero García 2022 年 11 月 7 日
Here I put the animation in mp4 for you:
I hope you like it...!!!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by