Matlab画曲线的切向量-quiver函数的应用

如果对曲线 y = y ( x ) y=y(x) y=y(x)上每一个点 ( x 0 , y 0 ) (x_{0},y_{0}) (x0,y0) F ⃗ ( x 0 , y 0 ) \vec{F}(x_{0},y_{0}) F (x0,y0) 是曲线的切线,
在这里插入图片描述

那曲线 y = y ( x ) y=y(x) y=y(x) 的切线场可以用一个矢量函数 F ⃗ ( x , y ) = i ⃗ F x ( x , y ) + F y ( x , y ) \vec{F}(x,y)=\vec{i}F_{x}(x,y)+F_{y}(x,y) F (x,y)=i Fx(x,y)+Fy(x,y)来描述,并且 d y d x = F y ( x , y ) F x ( x , y ) \frac{dy}{dx} = \frac{F_{y}(x,y)}{F_{x}(x,y)} dxdy=Fx(x,y)Fy(x,y)

在Matlab中,我们可以使用quiver函数来画一个曲线的切线场。
代码示例:

%% draw the fuction curve of y = sqrt(2 + x.^2) and its quiver plot
%drawn the function plot
x = -2:0.1:2;
y = sqrt(2 + x.^2);
plot(x,y);
text(-1.2, 2, '$\leftarrow y = \sqrt{x^2 + 1} $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
hold on

% draw the quiver plot
fx = y;
fy = x;
scale = 0.2;
quiver(x,y,fx, fy,scale,'r','LineWidth',1)
text(0.5, 1.2, '$\vec{F}(x,y)=\vec{i}x + \vec{j}y$', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
axis equal
hold off

运行结果:
在这里插入图片描述
代码示例-2:

%%  draw the velocity vector arrow of the vector function i*y + j*x at its varisou interal function


x = -1:0.1:1; % x-axis for plotting
c = 0:0.25:1; % different integral constants

%create X,Y matrix for plottig 
X = (x')*(ones(1,length(c)));
C = (ones(length(x),1))*c;
Y = sqrt(2.*C + X.^2);

plot(X,Y);
hold on
%% quiver plottting
fx = Y;
fy = X;
scale = 0.2;
quiver(X,Y,fx, fy,scale,'r')
text(-0.2, 1.6, '$\vec{F}(x,y)=\vec{i}y + \vec{j}x$', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
axis equal
grid on
hold off

输出结果为:
在这里插入图片描述

附录:
第一张图的源代码

%% draw the fuction curve of y = sqrt(2 + X.^2) and one of its tangential vectors
%drawn the function plot
x = -2:0.1:2;
y = sqrt(2 + x.^2);
plot(x,y);
text(-1.2, 2, '$\leftarrow y = \sqrt{x^2 + 1} $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
hold on

% draw the tangential vecotr at position x(i),y(i), i = 25
fx = y;
fy = x;
scale = 0.5;
i = 25;
quiver(x(i),y(i),fx(i), fy(i),scale,'r','LineWidth',2)
text(1.2, 1.7, '$\vec{F}(x_{0},y_{0})$', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
axis equal
hold off
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页