I have trouble when plot with quiver

can you help me to fix this script . I want to plot a potrait phase with arrow , but this script just run on matlab 2021a. but,
my matlab ver. 2007.
clc; clear;
figure1=figure;
axes1=axes('Parent',figure1,'fontsize',13);
grid on;
box(axes1,'on');
hold(axes1,'all');
to = 0;
tf = 30;
tspan = to:0.1:tf;
plotArrows = @(m) quiver(m(:,1), m(:,5), gradient(m(:,1)), gradient(m(:,5)));
figure
iv1 = [ 12.3 0.1 0 0.1 0.1 ] ;
[t y] = ode45(@(t, y) lnear(t, y), tspan, iv1);
plotArrows(y), hold on
iv2 = [ 12.3 0 0 0 0 ] ;
[t x] = ode45(@(t, x) lnear(t, x), tspan, iv2);
plotArrows(x),
iv3 = [ 12.65 0 0 0.1 0.1 ] ;
[t z] = ode45(@(t, z) lnear(t, z), tspan, iv3);
plotArrows(z),
iv4 = [ 12.65 0.1 0.1 0 0 ] ;
[t n] = ode45(@(t, n) lnear(t, n), tspan, iv4);
plotArrows(n),
iv5 = [ 12.485594 0 0 0 0.12 ] ;
[t w] = ode45(@(t, w) lnear(t, w), tspan, iv5);
plotArrows(w),
iv6 = [ 12.3 0.1 0 0.1 0 ] ;
[t v] = ode45(@(t, v) lnear(t, v), tspan, iv6);
plotArrows(v),
iv7 = [ 12.4 0.05 0 0.05 0 ] ;
[t s] = ode45(@(t, s) lnear(t, s), tspan, iv7);
plotArrows(s),
iv8 = [ 12.65 0.05 0 0.05 0.05 ] ;
[t p] = ode45(@(t, p) lnear(t, p), tspan, iv8);
plotArrows(p),
iv9 = [ 12.6 0.05 0 0.05 0 ] ;
[t c] = ode45(@(t, c) lnear(t, c), tspan, iv9);
plotArrows(c), grid on
xlabel('y_1'), ylabel('y_5')
function dydt = lnear(t,y)
dydt = zeros(5, 1);
e1 = 13;
g = 0.0125;
h = 0.284253;
f = 0.05;
q1 = 0;
k1 = 10;
d1 = 0.0412;
e2 = 0.0188;
j = 0.0082;
q2 = 0;
k2 = 10;
d2 = 0.0288;
b = 2;
d4 = 0.1152;
e3 = 0.166667;
a = 1.7;
q3 = 0;
k3 = 10;
d3 = 0.1152;
r = 0.5;
m = 1.02;
q4 = 0;
k4 = 10;
dydt(1) = e1 + (g*y(3)*y(1)/(h + y(3))) + (f*y(3)*y(1)) - (y(1)*(1 + ((q1/k1)*y(1)))) - (d1*y(1));
dydt(2) = e2*y(2) + (f*y(1)*y(3)) - (j*y(2)) - (y(2)*(1 + ((q2/k2)*y(2)))) - (d2*y(2));
dydt(3) = (b*e2*y(2)) - (d4*y(3));
dydt(4) = e3*y(4) + (j*y(2)) - (a*y(4)) - (y(4)*(1 + ((q3/k3)*y(4)))) - (d3*y(4));
dydt(5) = (r*y(5)*(1 - (m*y(5)))) + (a*y(4)) - y(5)*(1 + ((q4/k4)*y(5)));
end

回答(1 个)

4 个评论

Copy only the function code to a new window (tab) in the MATLAB Editor, then save the function in a file named lnear.m and the code should then work correctly. Also, delete it from the script file that contains the rest of the code and then save the script file.
If possible, upgrade to the latest MATLAB release.
Thank you so much. Matlab coding still has an error even thouh I'm already save the function in a file names lnear.m and using the 2015 version of Matlab. I have new coding matlab for phase portrait using equiver but the arrow in portrait phase not clearly visible. Can you help me please
This is the function name
function dy=fungsipotretfasepemodelanedit(t,y)
global k a1 a2 b1 b2 e1 e2 m r q s w1 w2 ;
dy=zeros(5,1);
dy(1)= k+(e2*y(1)*y(2))-(a1*y(1)*y(3))-(e1*y(1)*y(2))-(m*y(1))-(b1*y(1)*y(4)) ;
dy(2)=(e1*y(1)*y(2))-(a2*y(2)*y(3))-(b2*y(2)*y(4))-(m*y(2))-(e2*y(1)*y(2));
dy(3)= (a1*y(1)*y(3))+(a2*y(2)*y(3))-(w1*y(3))-(m*y(3))-(r*y(3))-(s*y(3)*y(4));
dy(4)= (b1*y(1)*y(4))+(b2*y(2)*y(4))-(m*y(4))-(w2*y(4));
dy(5)= (w1*y(3))+(w2*y(4))+(s*y(3)*y(4))-(m*y(5))-(q*y(5));
end
and this is coding for runing the coding matlab
clc; close all; clear all;
figure1 = figure ;
axes1 = axes ( 'Parent' , figure1 , 'fontsize' , 13 ) ;
grid on;
box(axes1,'on') ;
hold(axes1,'all') ;
plotArrows = @(m) quiver(m(:,1),m(:,2), gradient(m(:,1)), gradient (m(:,2)));
global k e1 e2 a1 a2 b1 b2 m r q w1 w2 s;
k=40;
e1=0.07;
e2=0.05;
a1=0.08;
a2=0.02;
b1=0.07;
b2=0.03;
m=0.2;
r=0.03;
q=0.05;
w1=0.4;
w2=0.47;
s=0.02;
[t1,y1]=ode45(@fungsipotretfasepemodelanedit,[0 1000],[20 20 10 20 5]);
[t2,y2]=ode45(@fungsipotretfasepemodelanedit,[0 1000],[20 18 10 50 20]);
[t3,y3]=ode45(@fungsipotretfasepemodelanedit,[0 1000],[50 10 90 40 20]);
[t4,y4]=ode45(@fungsipotretfasepemodelanedit,[0 1000],[10 50 90 40 10]);
figure(1);
plot(y1(:,1), y1(:,2),'blue',y2(:,1), y2(:,2),'red',y3(:,1),y3(:,2),'green',y4(:,1),y4(:,2),'black','linewidth',2);
plotArrows(y1),
plotArrows(y2),
plotArrows(y3),
plotArrows(y4),
legend('Nilai Awal 1','Nilai Awal 2','Nilai Awal 3','Nilai Awal 4');
xlabel('Jumlah Populasi Rentan yang Memiliki Berat Badan Normal');
ylabel('Jumlah Populasi Rentan yang Obesitas');
%R0=sqrt((gamma*k1*beta*k2*alfa)/(d*(alfa+m)*(delta+m)))
that is result of running coding matlab

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Vector Fields 的更多信息

产品

版本

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by