I'm new to solving ode's in Matlab, i followed tutorial, and i do not understand the error
1 view (last 30 days)
Show older comments
%this is my fxn file
function [Ddv_Div] = ASFxn(Ind,D)
%IV, Ind, IVsol - independent variables
% DV, D, DVsol - Dependent variables
%S - uninfected and susceptible to infection
%I - infected and able to transmit the virus
%C - survivor individuals which do not transmit the virus but can revert to
%the infected (I) class
%D - infected carcasses which can transmit the virus
%a(t) -seasonal birth rate
% bp, ba, bh, mortality rate in the absence of the disease (natural death
% of piglets and adults and death by hunting)
% k is the carrying capacity
%Bf frequenct dependent transmission, though contact with infected
%individual.
%Be environmental transmission through contact with an infected carcass.
Sp = D(1);
Sa = D(2);
Ip = D(3);
Ia = D(4);
Cp = D(5);
Ca = D(6);
D = D(7);
Bf = 63;
Be = 2;
rho = 0.85;
bc = 0;
r = 0;
I = Ip + Ia; %the total infected population
A = Sp + Ia +Ca; % the total adult population
N = Sp + Sa + Ip + Cp + Ca; %the total population of living wild boar
Alpha = 12/10; %average maturation of piglets to adults within 10 months
a_t = (3/2)*A;
bh = 0.69;
ba = 0.05;
b0 = log(2);
k = 2; %2Km^-2 in natural populations and 4 Km^-2 under supplementary feeding
Sig = k/(Sp+Sa+Cp+Ca+Ia+Ip);%the scaling term use to ensure that average population density equals the carrying capcity
b1 = Sig*((a_t*Alpha-b0*(ba+bh))/(ba+ba)*k);
bp = (b0+b1*N);
y = 365/5; % a portion, rho, of individuals suffer disease induced mortality at rate y =365/5.
% a portion of 1 - rho of infected can enter the survivor class,
% which does not incur disease induced mortality.
kk = 16/6; % rate at whick survivors can revert back to the infeted class (where they incure disease induced mortality. The value implies that the average time spent in the survivor class is 6 months.
d = 52/8; % decay rate for carcasses. Individuals that dies whilst infected are classed as infected carcasses can transmit infection for on average 8 weeks.
% to initiate the model
I = k * (0.2/100); % a low level of infection.
Ddv_Div =[ a_t*A - Bf*(Sp/N)*I - Be*Sp*D - Alpha*Sp - bp*Sp - bc*Sp;
-Bf*(Sa/N)*I - Be*Sp*D - Alpha*Ip - y*Ip + kk*Cp - bp*Ip - bc*Ip;
Bf*(Sa/N)*I - Be*Sa*D - Alpha*Ip -y*Ip + kk*Cp - bp*Ip - bc*Ip;
Bf (Sa/N)*I - Be*Sa*D - Alpha*Ip - y*Ia + kk*Ca - ba*Ia - bh*Ia - bc*Ia;
y*(1-rho)*Ip - kk*Cp - Alpha*Cp - bp*Cp - bc*Cp;
y*(1-rho)*Ia - kk*Ca + Alpha*Cp - ba*Ca - bh*Ca - bc*Ca;
y*rho + bp*Ip - ba*Ia - d*D - r*D; ];
end
%this is my script
domain = [0 12];
IC1 = 100; %initial number of piglets susceptible to the virus
IC2 = 90; %initial number of Adult pigs susceptible to the virus
IC3 = 12; %initial number of piglets infected with the virus
IC4 = 8; %initial number of Adult pig infected with the virus
IC5 = 1; %initial number of survivor piglets which do not transmit the virus but can contract again
IC6 = 1; %initial number of survivor adults which do not transmit the virus but can contract again
IC7 = 3; %initial number of infected carcasses which can transmit the virus
IC = [IC1 IC2 IC3 IC4 IC5 IC6 IC7];
[IVsol, DVsol] = ode45('ASFxn',domain,IC);
%-------this is the error i get when i run the script-----%
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
3 Comments
Atsushi Ueno
on 13 May 2021
Also, your code has lack of "*" (asterisk for multiplication).
Bf (Sa/N)*I - Be*Sa*D - Alpha*Ip - y*Ia + kk*Ca - ba*Ia - bh*Ia - bc*Ia;
Accepted Answer
Cris LaPierre
on 13 May 2021
Edited: Cris LaPierre
on 13 May 2021
The dimension error is due to this line, with the problematic part indicated:
[...
Bf*(Sa/N)*I - Be*Sa*D - Alpha*Ip -y*Ip + kk*Cp - bp*Ip - bc*Ip;
% ^^
];
When building an array using square brackets, you either need to have a space between your minus sign and the following expression, or no spaces on either side. When inside square brackets, the "-y*Ip" is saying 'negative y times Ip' and not 'minus', resulting in two separate numbers.
As a simplified example, consider the following
% With square brackets
[5 - 3]
[5 -3]
[5-3]
% Without square brackets
5 - 3
5 -3
5-3
With this fixed and the missing * added in the 4th line (after Bf), the code runs without error, though it does not arrive at a solution.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!