SimBiology

SimBiology

Public Channel

Paulo in MATLAB Answers
Last activity on 22 May 2026

When a MassAction rate parameter (e.g., `ke`) is set by an initial assignment rule, `createSimFunction` does not use the computed value for the MassAction rate calculation. The parameter IS correctly computed (confirmed by observing it as a SimFunction output), but MassAction uses the pre-assignment `.Value` property instead. `sbiosimulate` with the same model produces correct results. Environment - MATLAB R2025b (25.2.0.3123386) - SimBiology toolbox model = sbiomodel("MWE"); cs = getconfigset(model); cs.SolverType = 'sundials'; cs.SolverOptions.AbsoluteTolerance = 1e-8; cs.SolverOptions.RelativeTolerance = 1e-8; cs.CompileOptions.DimensionalAnalysis = true; cs.CompileOptions.UnitConversion = true; addcompartment(model, 'Central', ... 'CapacityUnits', 'milliliter', 'ConstantCapacity', false); addspecies(model.Compartments(1), 'Drug', 0, 'Units', 'milligram/milliliter'); addparameter(model, 'typical_V', 3000, 'Units', 'milliliter'); addparameter(model, 'typical_CL', 200, 'Units', 'milliliter/hour'); addparameter(model, 'BW', 70, 'Units', 'kilogram'); addparameter(model, 'typical_BW', 70, 'Units', 'kilogram'); addparameter(model, 'CL', eps, 'Units', 'milliliter/hour'); addparameter(model, 'ke', eps, 'Units', '1/hour'); % Initial assignments: % Central = 3000 mL, CL = 200 mL/h, ke = 200/3000 = 0.0667 /h addrule(model, 'Central = typical_V * (BW / typical_BW)', 'initialAssignment'); addrule(model, 'CL = typical_CL * (BW / typical_BW)', 'initialAssignment'); addrule(model, 'ke = CL / Central', 'initialAssignment'); % MassAction elimination (first-order) rxn = addreaction(model, 'Central.Drug -> null', 'Name', 'Elimination'); kl = addkineticlaw(rxn, 'MassAction'); kl.ParameterVariableNames = 'ke'; % Dose dose = sbiodose('IV', 'schedule'); dose.TargetName = 'Drug'; dose.Amount = 300; dose.AmountUnits = 'milligram'; dose.TimeUnits = 'hour'; dose.Time = 0; % --- Method 1: createSimFunction (INCORRECT) --- F = createSimFunction(model, {}, {'Drug', 'ke', 'CL', 'Central'}, {'Central.Drug'}, ... 'UseParallel', false, 'AutoAccelerate', false); [~, y] = F([], [], getTable(dose), [0, 10, 100]); fprintf('createSimFunction:\n'); fprintf(' Drug(t=0)=%g, Drug(t=10h)=%g, Drug(t=100h)=%g\n', y{1}(1,1), y{1}(2,1), y{1}(3,1)); fprintf(' ke=%g, CL=%g, Central=%g (all correct!)\n\n', y{1}(1,2), y{1}(1,3), y{1}(1,4)); % --- Method 2: sbiosimulate (CORRECT) --- cs.StopTime = 100; cs.TimeUnits = 'hour'; cs.SolverOptions.OutputTimes = [0, 10, 100]; [~, x, names] = sbiosimulate(model, cs, [], dose); idx = strcmp(names, "Drug"); fprintf('sbiosimulate:\n'); fprintf(' Drug(t=0)=%g, Drug(t=10h)=%g, Drug(t=100h)=%g\n', x(1,idx), x(2,idx), x(3,idx)); Output createSimFunction: Drug(t=0)=0.1, Drug(t=10h)=0.0999815, Drug(t=100h)=0.099815 ke=0.0666667, CL=200, Central=3000 (all correct!) sbiosimulate: Drug(t=0)=0.1, Drug(t=10h)=0.0513417, Drug(t=100h)=0.000127269 Expected Behavior Both methods should produce identical results. Expected half-life = ln(2) / 0.0667 = 10.4 hours. `sbiosimulate` is correct; `createSimFunction` shows ~1000x slower elimination. Key Observation The initial assignments ARE evaluated correctly in `createSimFunction` — `ke=0.0667`, `CL=200`, `Central=3000` are all reported with correct values when observed as SimFunction outputs. However, the MassAction rate calculation does not use the computed `ke` value; it appears to use the pre-assignment `.Value` (eps). Notes - This pattern (`ke = CL/V` as initial assignment, MassAction with `ke`) is the same pattern used by SimBiology's own `PKCompartment.m` source code for "linear-clearance" elimination (lines 132-142 in R2025b). - The issue is not specific to chained initial assignments — even `ke = typical_CL / typical_V` (single-level, depending only on directly-set parameters) exhibits the same behavior. - The `Constant` property of the parameters does not affect the outcome. - `AutoAccelerate = true` does not fix the issue.
MathWorks Support Team in MATLAB Answers
Last activity on 30 Jan 2024

SimBiology Model Analyzer の Fit Data タスクを実行すると、 Integration Tolerance Not Met のエラーが発生します。回避方法を教えてください。 kA031000000TCuvCAG 000068315
MathWorks Support Team in MATLAB Answers
Last activity on 11 Jan 2024

I am running a Fit Data task in Simbiology for a two step model: L + A <---> LA LA + BG <---> C The reaction rate for the two reactions are respectively: kon1*A*L - koff1*LA kon2*LA*BG - koff2*C I am using the concentration of C as my independent / response variable and time as my dependent / predictor variable to estimate the parameter "kon2"; the other three parameters are known. Every time I run the simulation, I get the following error: Integration Tolerance Not Met I have tried changing i) the initial value of "kon2", ii) the tolerance and number of iterations, and iii) the solver used to estimate the parameter, to no avail. What could be causing this error and how can I resolve this? kA031000000TCuvCAG 000068315
Wenye Deng in MATLAB Answers
Last activity on 17 Feb 2023

I followed the video https://www.mathworks.com/videos/building-a-model-in-simbiology-68960.html?s_tid=srchtitle_drag%20a%20line%20to%20create%20reaction_1 to create a model. But I cannot drag a line between two species to create a reaction. What did I miss?
Shivam Thakker in MATLAB Answers
Last activity on 25 Jun 2021

When I am writting a rate rule I am getting this above error message. My rule is LuxI = (1/Tx) ∗ (((tl_luxI ∗ [mRNA_luxI]) ∗ Tx) − ((dLuxI ∗ [LuxI]) ∗ Tx)) I have seen some of the error messages answers of Matlab but nothing worked in my case.Kindly help me with this.
emjey in MATLAB Answers
Last activity on 8 Jan 2018

While encoding a simple model of cell proliferation/death with rates r*X and d*X, which should result in an ODE such as dX/dt = r*X – d*X, I realised that it very much depends how the related 'Reaction' is formulated. With the correct stoichiometry 'B -> 2 B' all is fine but with 'B -> B' the growth flux is omitted entirely from the ODE. This is of course correct but it should come with a warning. I can imagin for complex model one is unable to verify whether the model is correctly interpreted and encoded. In this case the according reaction is visible in the diagram but the flux is not part of the relevant ODE. The question is: what are the other, if any, checks SimBiology performs behind the scenes which might result in differences between the model network and the model formulation?
Michael in MATLAB Answers
Last activity on 13 Dec 2015

Hi everyone, this feels like it should be easy, but I can't figure it out. I have a simple reaction A-->B following a given custom reaction rate. I want to add a delay. Using the event trigger I tried two approaches: # time<1800 B=0 # time<1800 Imax=0 (Imax is the reaction rate) However, in both cases the reaction is evaluated as if nothing ever changed. Any suggestions? What am I missing? (for completeness, in the actual model there are upstream components that funnel into A) Thanks a lot! Cheers, Michael