The code contains an expression too complex for code analysis to handle

8 views (last 30 days)
I’m working on a modified SEIR model that has a couple of states. However, each state is partitioned into many compartment. Hence, the number of terms in each differential equation becomes very large. I tried to use MATLAB ode23s to solve the differential equations and got the following warning, “The file is too complex to analyze. The code contains an expression too complex for code analysis to handle.”
One of the equations is like this.
dS1 = - S1*phi1*I1 - S1*phi2*I2 - S1*phi3*I3 - … - S1*phi144*I144 - S1*alpha1*P1 - S1*alpha2*P2 - S1*alpha3*P3 … - S1*alpha144*P144 - S1*theta1*E1 - S1*theta2*E2 - S1*theta3*E3 … - S1*theta144*E144;
That’s a total of 432 terms. The warning/error appears once the number of terms in the equation exceed 144.
Is there a limit to number of terms in a differential equation that can be solve using MATLAB? Any suggestion on how I can handle this problem?
Thanks in advance.
  9 Comments
Rik
Rik on 4 Aug 2021
You should only use single letter/numbered variables when it is obvious what they mean. What is obvious depends on context. The example you give is probably fine (since it should be clear that it is a single calculation broken into parts (that may or may not have meaning) to reduce typos and parsing complexity). However, using 300+ number variables is probably not the way to go. It doesn't make sense to assume there aren't any typos in such an expression without it being generated by some code. And if it is generated I don't really see why it couldn't have been generated as an array instead.
I'm not saying a swiss army knife shouldn't ever be used. I'm just saying you should consider other tools if you have a block of marble you want to sculpt.
But I suspect we mostly agree and that we're arguing over nuaces here.
Bjorn Gustavsson
Bjorn Gustavsson on 4 Aug 2021
dS1 = - S1*( phi_all(:).'*I_all(:) + alpha(:).'*P_all(:) + theta_all(:).'*E_all(:) );

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!