Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simplify and then discretize a set of equations with derivatives and integrals

49 views
Skip to first unread message

Matthieu Brucher

unread,
May 29, 2012, 5:45:39 AM5/29/12
to
Hi,

I'm new to Mathematica, but as I professionally have access to it, I'd
like to use it to simplify this problem.

I have a set of equations (from http://www.simulanalog.org/statevariable.pdf)
explaining how a simple electronic system works. My input is e(t) and
my output is vd(t). f(v) can be written as an exponential function
(f(v) = a * e^(b * v + c) for instance).
Here are the equastions :

eqns = {e[t] - i[t] * R - vc[t] - vd[t] == 0,
vc[t] == 1/C * Integrate[i[t], t],
i[t] == f[vd[t]]}

What I'd like is first to simplify this set of equations to a simple
one with only e(t) and vd(t). At one point, I could get the correct
result, but I could get the correct result after resetting the kernel.

Once this is done, I'd like to discretize the resulting function with
the bilinear transform.

Of course, it easy to get the result by hand in this case. But my next
set of equations is so complicated that I don't want to try to solve
it (my main issue is the first step, the discretization is 'just"
symbolic computation once the replacement is done), so I'm back at
Mathematica.

Is it possible do this in Mathematica? Is it complicated to do?

If someone has an answer...

Matthieu

Alexei Boulbitch

unread,
May 31, 2012, 2:47:20 AM5/31/12
to
Hi,

I'm new to Mathematica, but as I professionally have access to it, I'd
like to use it to simplify this problem.

I have a set of equations (from http://www.simulanalog.org/statevariable.pdf)
explaining how a simple electronic system works. My input is e(t) and
my output is vd(t). f(v) can be written as an exponential function
(f(v) = a * e^(b * v + c) for instance).
Here are the equations :

eqns = {e[t] - i[t] * R - vc[t] - vd[t] == 0,
vc[t] == 1/C * Integrate[i[t], t],
i[t] == f[vd[t]]}

What I'd like is first to simplify this set of equations to a simple
one with only e(t) and vd(t). At one point, I could get the correct
result, but I could get the correct result after resetting the kernel.

Once this is done, I'd like to discretize the resulting function with
the bilinear transform.

Of course, it easy to get the result by hand in this case. But my next
set of equations is so complicated that I don't want to try to solve
it (my main issue is the first step, the discretization is 'just"
symbolic computation once the replacement is done), so I'm back at
Mathematica.

Is it possible do this in Mathematica? Is it complicated to do?

If someone has an answer...

Matthieu

Hi, Matthieu,

Just to give an idea of what can easily be done. You can slightly rewrite the system as follows:

Clear[t];
f[v_] := a*Exp[b*v + c];
eqns = {e[t] - i[t]*R - vc[t] - vd[t] == 0, vc'[t] == CC^-1*i[t],
i[t] == f[vd[t]]}

Here I use CC instead of C, since in Mathematica C is reserved. There are besides an syntax error in the expression f(v) = a * e^(b * v + c). In addition the second equation is differential instead of the integral.
You may then eliminate the variable i[t]:

expr = Eliminate[eqns, i[t]]

the result is:

a E^(c + b vd[t]) == CC Derivative[1][vc][t] &&
vd[t] == e[t] - vc[t] - CC R Derivative[1][vc][t] && CC != 0

Its first and second parts are your desired equations. Indeed

expr[[1]]
expr[[2]]


E^(1 + vd[t]) == Derivative[1][vc][t]

vd[t] == Sin[t] - vc[t] - Derivative[1][vc][t]


This you may solve numerically, if you fix the function e[t] and parameters to be numeric. You can discretize it, but you need not.
Instead you might better apply the built-in function NDSolve. Have a look in Menu/Help/NDSolve. To give an idea, I put below all constants equal to 1, e[t]=Sin[t], and numerically solve the obtained system:

e[t_] := Sin[t];
c = 1; b = 1; CC = 1; a = 1; R = 1;

s = NDSolve[{expr[[1]], expr[[2]], vc[0] == 0}, {vc[t], vd[t]}, {t, 0,
30}][[1]] // Quiet

Execute it. The result is expressed in terms of two InterpolatingFunctions. To have a look what it gives, execute this:

Plot[Evaluate[{vc[t], vd[t]} /. s], {t, 0, 30}]

Finally, in this problem it was no need to exclude the variable, just solve all the three equations at once numerically.

I have chosen the initial values arbitrarily. Execute this:

e[t_] := Sin[t];
c = 1; b = 1; CC = 1; a = 1; R = 1;

s1 = NDSolve[{eqns, vc[0] == 0, vd[0] == 1, i[0] == 0}, {vc[t], vd[t],
i[t]}, {t, 0, 30}][[1]] // Quiet

and have a look at the result here:

Plot[Evaluate[{vc[t], vd[t], i[t]} /. s1], {t, 0, 30},
PlotStyle -> {Red, Green, Blue}]

Here red gives vc, green - vd and blue - i.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.b...@iee.lu




Matthieu Brucher

unread,
May 31, 2012, 2:52:57 AM5/31/12
to
Hi Alexei,

Thanks for the corrections and the advice. I will try it today.

Indeed, the plot can be interesting to validate my final implementation of
the problem. At the moment, I need to discretize it so that I can implement
the final equation solver in C++.

Thanks again,

Matthieu
--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher


dr DanW

unread,
Jun 1, 2012, 5:21:10 AM6/1/12
to
If you write the capacitor equation in derivative instead of integral form, your equation set is in the form of a Differential-Algebraic Equation (DAE) which I believe NDSolve could solve directly, even if f() is not invertable. Wolfram just released SystemModeler (formerly MathModelica) which is a system for formulating this sort of equation from a representation of a physical system and solving it. In the process, it generates c code of the equation set. If this is a one-time thing, maybe you could download the trial version of SystemModeler and extract the c code from your system. If you are doing this on a regular basis for your project, it might be worth giving SystemModeler a look.

Daniel

0 new messages