Adding Global Equations
To add a global equation in the model use the command:
model.component(<ctag>).physics.create(<odestag>, 'GlobalEquations')
To define the name of the variable to be solved by the global equation, enter:
ode.set('name', <idx>, <name>)
where ode is a link to a Global Equations node and <idx> is the index of the global equation, and <name> a string with the name of the variable.
Set the expression <expr> of the global equation with:
ode.set('equation', <idx>, <expr>)
where <expr> is defined as a string variable.
Initial value and initial velocity can be set with the commands:
ode.set('initialValueU', <idx>, <init>)
ode.set('initialValueUt', <idx>, <init_t>)
where <init> and <init_t> are the initial value expression for the variable and its time derivative respectively.
Example: Solve an ODE problem
This example illustrates how to solve the following ODE in a COMSOL model:
Code for use with MATLAB®
model = ModelUtil.create('Model');
comp1 = model.component.create('comp1', true);
ge = comp1.physics.create('ge', 'GlobalEquations');
ge1 = ge.feature('ge1');
ge1.set('name', 1, 1, 'u');
ge1.set('equation', 1, 1, 'utt+0.5*ut+1');
ge1.set('initialValueU', 1, 1, 'u0');
ge1.set('initialValueUt', 1, 1, 'u0t');
model.param.set('u0', 0);
model.param.set('u0t', 20);
std1 = model.study.create('std1');
std1.feature.create('time', 'Transient');
std1.feature('time').set('tlist', 'range(0,0.1,20)');
std1.run;
model.result.create('pg1', 1);
model.result('pg1').set('data', 'dset1');
model.result('pg1').feature.create('glob1', 'Global');
model.result('pg1').feature('glob1').set('expr', {'comp1.u'});
mphplot(model,'pg1')