-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectfield.m
More file actions
25 lines (25 loc) · 798 Bytes
/
vectfield.m
File metadata and controls
25 lines (25 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%vectfield vector field for system of 2 first order ODEs
% vectfield(func,y1val,y2val) plots the vector field for the system of
% two first order ODEs given by func, using the grid of y1val and
% y2 values given by the vectors y1val and y2val. func is either a
% the name of an inline function of two variables, or a string
% with the name of an m-file.
% By default, t=0 is used in func. A t value can be specified as an
% additional argument: vectfield(func,y1val,y2val,t)
function vectfield(func,y1val,y2val,t)
if nargin==3
t=0;
end
n1=length(y1val);
n2=length(y2val);
yp1=zeros(n2,n1);
yp2=zeros(n2,n1);
for i=1:n1
for j=1:n2
ypv = feval(func,t,[y1val(i);y2val(j)]);
yp1(j,i) = ypv(1);
yp2(j,i) = ypv(2);
end
end
quiver(y1val,y2val,yp1,yp2,'r');
axis tight;