Skip to content

Instantly share code, notes, and snippets.

@asonnino

asonnino/fmpc.nb Secret

Last active December 5, 2019 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asonnino/7d3abd570736d13bddf61fa429692983 to your computer and use it in GitHub Desktop.
Save asonnino/7d3abd570736d13bddf61fa429692983 to your computer and use it in GitHub Desktop.
Analytical example of simple FMPC computation (executable with Wolfram Mathematica).
(* define parameters *)
p = 0.5;
t2 = Pi/(4*l);
t4 = (3*Pi)/(4*l);
s2 = t4;
s4 = t2;
(* define mask functions *)
phiT[x_] := t1*Sin[t2*x] + t3*Cos[t4*x];
psiS[x_] := s1*Sin[s2*x] + s3*Cos[s4*x];
(* compute normalization coefficients *)
norm1 = (1/l*Integrate[phiT[x]*psiS[x], {x, -l, l}])^(-p);
norm2 = (1/l*Integrate[phiT[x]*psiS[x], {x, -l, l}])^(p - 1);
(* compute normalized mask functions *)
normPhiT[x_] := norm1 * phiT[x];
normPsiS[x_] := norm2 * psiS[x];
(* compute f and g *)
f[x_] := a * normPhiT[x];
g[x_] := b * normPsiS[x];
(* compute fourier coefficients *)
a0 = (1/l) * Integrate[f[x], {x, -l, l}];
an = (1/l) * Integrate[f[x] * Cos[(n* Pi *x)/l], {x, -l, l}];
bn = (1/l) * Integrate[f[x] * Sin[(n* Pi *x)/l], {x, -l, l}];
alpha0 = (1/l) * Integrate[g[x], {x, -l, l}];
alphan = (1/l) * Integrate[g[x] * Cos[(n* Pi *x)/l], {x, -l, l}];
betan = (1/l) * Integrate[g[x] * Sin[(n* Pi *x)/l], {x, -l, l}];
(* compute the product ab *)
node1 = a0*alpha0/2 + Sum[an*alphan, {n, 1, Infinity}];
node2 = Sum[bn*betan, {n, 1, Infinity}];
ab = node1 + node2;
(* print out *)
FullSimplify[a0, Element[n, Integers]]
FullSimplify[an, Element[n, Integers]]
FullSimplify[bn, Element[n, Integers]]
FullSimplify[alpha0, Element[n, Integers]]
FullSimplify[alphan, Element[n, Integers]]
FullSimplify[betan, Element[n, Integers]]
FullSimplify[ab]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment