How to export simbiology model as MATLAB code

조회 수: 20 (최근 30일)
T Abraham
T Abraham 2017년 10월 10일
편집: Arthur Goldsipe 2017년 10월 25일
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.

답변 (1개)

Arthur Goldsipe
Arthur Goldsipe 2017년 10월 10일
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
T Abraham
T Abraham 2017년 10월 22일
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 2017년 10월 25일
편집: Arthur Goldsipe 2017년 10월 25일
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!

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  SimBiology Community

카테고리

Help CenterFile Exchange에서 Scan Parameter Ranges에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by