function must return a column vector
4 views (last 30 days)
Show older comments
Hi, i am trying to plot some graphs for my my theses but i keep on getting error message..
find attached the code.. please help
function Juve_Model
clc;
%close all
global NO
%initial condition
Initial1 = [100,30,10,30];
hold on
for i=1:2:10
Initial=Initial1*i;
[t,u]=ode45(@hcv4,0:0.5:90, Initial);
subplot(2,2,1)
grid on
hold on
%axis([0 1400 0 1]);
plot(t,u(:,1),'linewidth',3);
xlabel('Time (days)')
ylabel('L')
%*********************************************
subplot(2,2,2)
grid on
hold on
plot(t,u(:,2),'linewidth',3);
xlabel('Time (days)')
ylabel('F_1')
%********************************************
subplot(2,2,3)
grid on
hold on
plot(t,u(:,3),'linewidth',3);
xlabel('Time (days)')
ylabel('F_2')
%*******************************************
subplot(2,2,4)
grid on
hold on
plot(t,u(:,4),'linewidth',3);
xlabel('Time (days)')
ylabel('M')
end
NO
end
function dy=hcv4(t,y)
%y=(L, F_1,F_2,M)=(y(1),y(2),y(3),y(4))
global NO
alpha=15; beta=0.1; q=0.3; gamma =0.7;
%beta=0.15; q=0.35; gamma=0.75;
K=1000; mu_L=0.35; d=0.45; mu_F1=0.15; mu_M=0.15; mu_F2=0.5;
% Basic Offspring (Reproduction) Number
NO=alpha*gamma*beta*q/(mu_F2*(mu_F1+gamma)*(beta+mu_L+d));
%Ordinary differential equation
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
end
0 Comments
Answers (1)
Torsten
on 28 Jul 2024
Edited: Torsten
on 28 Jul 2024
Allocate dy as a column vector before assigning values to it:
%Ordinary differential equation
dy = zeros(4,1);
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
And why do you need "NO" as a global variable ?
6 Comments
Torsten
on 28 Jul 2024
Edited: Torsten
on 28 Jul 2024
Juve_Model()
function Juve_Model
clc;
%close all
%initial condition
Initial1 = [100,30,10,30];
index = 0;
for i=1:2:10
Initial=Initial1*i;
[t,u]=ode45(@hcv4,0:0.5:90, Initial);
index = index + 1;
T{index} = t;
U{index} = u;
end
figure(1)
hold on
for i = 1:5
plot(T{i},U{i}(:,1),'linewidth',3)
end
hold off
grid on
xlabel('Time (days)')
ylabel('L')
figure(2)
hold on
for i = 1:5
plot(T{i},U{i}(:,2),'linewidth',3)
end
hold off
grid on
xlabel('Time (days)')
ylabel('F_1')
figure(3)
hold on
for i = 1:5
plot(T{i},U{i}(:,3),'linewidth',3)
end
hold off
grid on
xlabel('Time (days)')
ylabel('F_2')
figure(4)
hold on
for i = 1:5
plot(T{i},U{i}(:,4),'linewidth',3)
end
hold off
grid on
xlabel('Time (days)')
ylabel('M')
end
function dy=hcv4(t,y)
%y=(L, F_1,F_2,M)=(y(1),y(2),y(3),y(4))
alpha=15; beta=0.1; q=0.3; gamma =0.7;
%beta=0.15; q=0.35; gamma=0.75;
K=1000; mu_L=0.35; d=0.45; mu_F1=0.15; mu_M=0.15; mu_F2=0.5;
% Basic Offspring (Reproduction) Number
NO=alpha*gamma*beta*q/(mu_F2*(mu_F1+gamma)*(beta+mu_L+d));
%Ordinary differential equation
dy = zeros(4,1);
dy(1)=alpha*(1-y(1)/K)*y(3)-(beta+mu_L+d)*y(1);
dy(2)=beta*q*y(1)-(mu_F1+gamma)*y(2);
dy(3)=gamma*y(2)-mu_F2*y(3);
dy(4)=beta*(1-q)*y(1)-mu_M*y(4);
end
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!