Message Boards Message Boards

0
|
2114 Views
|
7 Replies
|
1 Total Likes
View groups...
Share
Share this post:

How to convert a discrete equation to a continuous equation

Posted 1 year ago

Firstly, in the program, X is a discrete expression about i (the specific analytical expression is in the For loop of the program), and the complete program is as follows:

{r = 22, l = 2 10^-1, c = 1 10^-4, vi = 24, initvalueil = 0, 
  initvaluevc = 0, tstart = 0, tend = 0.08, dt = 0.00006};
\[CapitalDelta]vi = 0;
n = (tend - tstart)/dt;
A = {{0, -1/l}, {1/c, -1/(r c)}};
G = Inverse[A];
B = {1/l, 0};
S1 = Inverse[DiagonalMatrix[{1, 1}] - dt*A + 1/2*dt*dt*A . A];
S2 = Inverse[DiagonalMatrix[{1, 1}] - dt*A];
STAR1 = S1 . G . (B*vi + G . B*\[CapitalDelta]vi/dt) - 
   G . (B*(vi + \[CapitalDelta]vi) + G . B*\[CapitalDelta]vi/dt);
STAR2 = S2 . G . (B*vi + G . B*\[CapitalDelta]vi/dt) - 
   G . (B*(vi + \[CapitalDelta]vi) + G . B*\[CapitalDelta]vi/dt);
X = Transpose[{{il, vc}}];
X0 = {0, 0};
errort = Table[tstart + dt*i, {i, 0, n}];
X1 = Table[{initvalueil, initvaluevc}, {i, 0, n}];
X2 = Table[{initvalueil, initvaluevc}, {i, 0, n}];
X = Table[{initvalueil, initvaluevc}, {i, 0, n}];
il = Table[0, {i, 0, n}];
vc = Table[0, {i, 0, n}];
For[i = 1, i < n + 1, i++,
  X[[i + 1]] = (MatrixPower[S1, i] - MatrixPower[S2, i]) . 
     X0 + (DiagonalMatrix[{1, 1}] . (DiagonalMatrix[{1, 1}] - 
         MatrixPower[S1, i]) . 
       Inverse[DiagonalMatrix[{1, 1}] - S1]) . 
     STAR1 - (DiagonalMatrix[{1, 1}] . (DiagonalMatrix[{1, 1}] - 
         MatrixPower[S2, i]) . 
       Inverse[DiagonalMatrix[{1, 1}] - S2]) . STAR2;
  il[[i + 1]] = X[[i + 1, 1]];
  vc[[i + 1]] = X[[i + 1, 2]];
  ];
p1 = Table[Transpose[{errort, il}], 1];
p2 = Table[Transpose[{errort, vc}], 1];
ListLinePlot[p1, AxesLabel -> {"s", "il[t]/A"}, 
 PlotLegends -> {"0.00006"}, PlotStyle -> {Red}, PlotRange -> All]
ListLinePlot[p2, AxesLabel -> {"s", "vc[t]/V"}, 
 PlotLegends -> {"0.00006"}, PlotStyle -> {Blue}, PlotRange -> All]

The curve obtained after executing the program is as follows: enter image description here

Next, I will replace i in the original X formula with t and dt, where dt is a constant and t is a variable. The complete program is as follows:

{r = 22, l = 2 10^-1, c = 1 10^-4, vi = 24, initvalueil = 0, 
  initvaluevc = 0, tstart = 0, tend = 0.08, dt = 0.00006};
\[CapitalDelta]vi = 0;
A = {{0, -1/l}, {1/c, -1/(r c)}};
G = Inverse[A];
B = {1/l, 0};
S1 = Inverse[DiagonalMatrix[{1, 1}] - dt*A + 1/2*dt*dt*A . A];
S2 = Inverse[DiagonalMatrix[{1, 1}] - dt*A];
STAR1 = S1 . G . (B*vi + G . B*\[CapitalDelta]vi/dt) - 
   G . (B*(vi + \[CapitalDelta]vi) + G . B*\[CapitalDelta]vi/dt);
STAR2 = S2 . G . (B*vi + G . B*\[CapitalDelta]vi/dt) - 
   G . (B*(vi + \[CapitalDelta]vi) + G . B*\[CapitalDelta]vi/dt);
X = Transpose[{{il, vc}}];
X0 = {0, 0};
X = ReplaceAll[(MatrixPower[S1, i] - MatrixPower[S2, i]) . 
     X0 + (DiagonalMatrix[{1, 1}] . (DiagonalMatrix[{1, 1}] - 
         MatrixPower[S1, i]) . 
       Inverse[DiagonalMatrix[{1, 1}] - S1]) . 
     STAR1 - (DiagonalMatrix[{1, 1}] . (DiagonalMatrix[{1, 1}] - 
         MatrixPower[S2, i]) . 
       Inverse[DiagonalMatrix[{1, 1}] - S2]) . STAR2, i -> t - dt];
il = X[[1]] // FullSimplify;
vc = X[[2]] // FullSimplify;

Plot[il, {t, tstart, tend}]
Plot[vc, {t, tstart, tend}]

The curve obtained after executing the program is as follows: enter image description here

It is obvious that the curves are different. Where did I go wrong, or how did I convert a discrete equation to a continuous equation?

POSTED BY: James James
7 Replies

This is difficult because your initial code is so very 'non-Wolfram-like'. Pre-making lists and writing into them, a For loop that looks like an iterative process but isn't, and various lines that are redundant. Here is a simple version that makes functions out of the main calculations, and then just plots them as continuous lines. I suggest you take a look and see how it works.

However, if you change the value of dt (in my code or yours), the resulting graphs have exactly the same shape but different y-axis values. So your calculations are not just replicating a continuous function using discrete time steps — something is wrong. There is surely a version that removes the need for dt at all.

POSTED BY: Gareth Russell

I also note that your \[CapitalDelta]vi=0, which could simply things further. But I assume you want to keep the option where it isn't zero.

POSTED BY: Gareth Russell
Posted 11 months ago

Thank you, sir. I am not familiar with the Wolfram language yet. In the future, I will try my best to write code in the Wolfram language format. Additionally, I have a new question on my homepage. Sir, if it's convenient, could you please help me take a look.

POSTED BY: James James

Sorry, I am not familiar with this kind of problem.

POSTED BY: Gianluca Gorni
Posted 1 year ago

Okay, thank you!

POSTED BY: James James

Try this:

Plot[il, {t, 0, 1335}]
Plot[vc, {t, 0, 1335}]
POSTED BY: Gianluca Gorni
Posted 1 year ago

Sir, what should I do if I want to convert a discrete domain into a time domain?

POSTED BY: James James
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract