[Getdp] Can I concatenate functions in GetDP?
Christophe Geuzaine
cgeuzaine at ulg.ac.be
Sat Nov 26 18:48:49 CET 2016
> On 26 Nov 2016, at 16:25, junniers romero <junniersromero at gmail.com> wrote:
>
> Hollo Mr. Geuzaine,
>
> I'm very pleased and thankful for the last material you sent me. It's come quite handy. Now, I'm trying to implement a VSD's voltage source in the machine's model scripts. Since I need the Fourier approximation with many terms, I was wandering whether it's possible to build a global function by concatenating the same function N times via a For loop? For example:
>
> For n In {1:1000}
> Wave_VSD [] += Wave_VSD + (1/n)*(Cos(n)Sin(n*2*Pi*$Time)) ;
> EndFor
> ; where (n) changes according to the For loop increment.
>
You can, but it's a bit tricky: the idea is that you can create and append to a string, and then parse the string
str = "Wave_VSD[] = 42";
For n In {1:1000}
str = StrCat[str, Sprintf["+(1/%g)*(Cos[%g]*Sin[%g*2*Pi*$Time])", n, n, n]];
EndFor
str = StrCat[str, ";"];
Parse[str];
You'll need a fairly recent version of GetDP for this (the "Parse" function is rather new).
CC:ing the list, as this might be useful to other people, too.
Christophe
> Thank you very much again, I'd appreciate your help deeply.
>
> Best Regards,
>
> Junniers Romero
>
> Venezuela - South America
> Simón Bolívar University
> Undergrad-Student
--
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine
Free software: http://gmsh.info | http://getdp.info | http://onelab.info
More information about the getdp
mailing list