How to export simbiology model as MATLAB code

17 views (last 30 days)
Is it possible to export the equations and the model parameters from SimBiology into the MATLAB workspace so it can be used with MATLAB ODE solvers like ode45? I know there is getequations, but that is a character array. Probably something to export the equations as a function? I specify the equations and the parameters, because I want to be able to edit them with ease. So most likely, the exported function for use with ODE solvers would not use any SimBiology functions.
This probably does not make much sense and such functionality probably does not exist, so please let me know if something is not clear or if this function does not exist currently.

Answers (1)

Arthur Goldsipe
Arthur Goldsipe on 10 Oct 2017
I suggest taking the output from getequations and saving it to a file. You may be able to manually edit that file to create a function suitable for use with ode45.
  2 Comments
T Abraham
T Abraham on 22 Oct 2017
How might I create a function suitable for ode45 use from the getequations output? also, getequations does not provide the rules for assignments of variables... is there a way to display that?
Arthur Goldsipe
Arthur Goldsipe on 25 Oct 2017
Edited: Arthur Goldsipe on 25 Oct 2017
Sorry I didn't see your follow-up question sooner. (I don't get notified when comments are posted.)
Let me answer your second question first. When you say that getequations does not provide the rules for assignments of variables, I assume you are referring to initial assignment rules? Because repeated assignment rules do appear in the output from getequations. Initial assignment rules are evaluated to determine the output in the "Initial Conditions" section of the output from getequations. So you can just copy those numeric values. If you really want the text representation of initial assignments, you can always get those from the "Rule" property of each corresponding Rule object.
Now to your first question. You need to rearrange and edit the different sections of output from getequations to something that makes sense for ode45. Typically, this means reordering the sections so that parameter values are defined first, then repeated assignment rules (if applicable), then fluxes, then ODEs. You will also need to convert to/from representing the species or ODES and a single vector versus separate scalar variables.
Here's an example of what I mean. Look at the output from getequations for the example model radiodecay:
ODEs:
d(x)/dt = -ReactionFlux1
d(z)/dt = ReactionFlux1
Fluxes:
ReactionFlux1 = c*x
Parameter Values:
c = 0.5 1/second
unnamed = 1 liter
Initial Conditions:
x = 1000 molecule
z = 0 molecule
Here's one way to convert that to a function for use with ode45:
function ODEs = radiodecay(time,allSpecies)
% Convert the vector of all species to separate variables for each
% individual species.
x = allSpecies(1);
y = allSpecies(2);
% Parameter Values:
c = 0.5; % 1/second
unnamed = 1; % liter
% Fluxes:
ReactionFlux1 = c*x;
% ODEs:
dx_dt = -ReactionFlux1;
dz_dt = ReactionFlux1;
ODEs = [dx_dt; dz_dt];
If you have additional questions, I suggest creating a new MATLAB Answers post to get a response in a more timely fashion.
Good luck!

Sign in to comment.

Communities

More Answers in the  SimBiology Community

Categories

Find more on Scan Parameter Ranges in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!