MATLAB Answers

0

"Struct contents reference from a non-struct array object." What does this mean?

Asked by Fellippe Amor on 3 Feb 2018
Latest activity Answered by John D'Errico
on 3 Feb 2018

I'm a high school student and I'm currently modifying the SIR Model for infectious diseases. I know so little about matlab since I only started yesterday and I keep receiving this error message: "Struct contents reference from a non-struct array object."

My code is here:

% Parameters for Beta
dt=1/7;                          %time interval i.e., per day
d= 0.0018288;                    %transmission diameter
v= 8.04672*7;                    %velocity in km/week
p= 98111/56.81;                  %density in person/km^3
c= sqrt(2)*pi*d^2*v*p;           %No. of contacs sigma in person/week
inf= 0.569;                      %Infection probability
beta=c*inf;                      %Beta
%Constants:
gr= 0.025;                       %growth rate 2.5%
rp= 0.18125;                     %probability of recovery
dp= 0.173125;                    %probability of death
dr= -0.00790639/52;              %death rate per week
br= 0.01296648/52;               %birth rate per week
%Simulation Codes
syms s(t) in(t) r(t) d(t) n(t)
eqn1= diff(s)== -beta*((in*s)/n)+(s*(dr+br));                %susceptibles
eqn2= diff(in)== beta*((in*s)/n)-rp*in-dp*in+(in*(dr+br));   %infectives
eqn3= diff(r)== rp*in+(r*(dr+br));                           %recovered
eqn4= diff(d)== dp*in;                                       %dead
eqn5= diff(n)== n*(dr+br);
S= dsolve(eqn1, eqn2, eqn3, eqn4, eqn5)
sSol(t)= S.s
inSol(t)= S.in
rSol(t)= S.r
dSol(t)= S.d
nSol(t)= S.n

Please help with this. Thank you very much!

  1 Comment

@Fellippe Amor: please show us the complete error message. This means all of the red text.

Sign in to comment.

1 Answer

Answer by John D'Errico
on 3 Feb 2018

When you try to run the above code, why not read the warning messages too? This is what dsolve returns:

S= dsolve(eqn1, eqn2, eqn3, eqn4, eqn5)
Warning: Unable to find explicit solution. 
> In dsolve (line 201) 
S =
[ empty sym ]

So of course the later assignment must fail, because dsolve failed before that step. You are trying to assign something that does not exist, at least, not in the eyes of dsolve.

  0 Comments

Sign in to comment.