Hi Christy,
The error message you've received about computing complex results usually indicates that a mathematical operation within your function is being performed on a value (or set of values) that is not within the valid domain of that operation. Common operations that can lead to this issue include square roots of negative numbers, logarithms of negative numbers, or improper use of exponents that result in complex numbers.
In your function, there are several operations that could potentially lead to domain errors if the inputs are not within a valid range.
I'll recommend you to follow below checks:
- Verify Mathematical Formulas: Double-check the mathematical formulas against your model or literature to ensure they are implemented correctly. Pay special attention to the units and make sure they are consistent across all calculations.
- Check Initial and Boundary Conditions: Ensure that all initial conditions (Cx0, Ce0, V0, etc.) and boundary conditions (like F, Csf, etc.) are physically plausible and within a realistic range. Incorrect initial conditions could lead to unexpected values that cause domain errors.
- Debugging Step-by-Step: Consider adding breakpoints or disp statements in your function to print out intermediate values of variables like u, Yxs, Yes, and the derivatives. This can help identify exactly where invalid values are first introduced.
- Correct dVdt Calculation: Review and correct the dVdt calculation to accurately reflect the rate of change of volume in the reactor, likely just dVdt = F.
You can check this post for better understanding of issue: https://www.mathworks.com/matlabcentral/answers/229261-runtime-error-call-to-matlab-function-aborted-domain-error-to-compute-complex-results-make-at-l
I hope it helps!