[Getdp] Can I concatenate functions in GetDP?

Patrick Dular Patrick.Dular at ulg.ac.be
Sat Nov 26 20:14:58 CET 2016


Hello,

For such a recursive definition, another solution could be this one, 
using an index appended to the name of successive functions with 
~{expression-cst}:

  Wave_VSD~{0} [] = 0.;
  For n In {1:4}
    Wave_VSD~{n} [] = Wave_VSD~{n-1} [] + (1/n)*(Cos[n]*Sin[n*2*Pi*$Time]) ;
  EndFor

Regards,

Patrick


On 26/11/16 18:48, Christophe Geuzaine wrote:
>> 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

-- 
Patrick Dular, Prof. Dr. Ir.,
Research Director F.R.S.-FNRS
Department of Electrical Engineering and Computer Science
Unit of Applied and Computational Electromagnetics (ACE)
University of Liege - Montefiore Institute - B28 - Parking P32
B-4000 Liege - Belgium - Tel. +32-4 3663710 - Fax +32-4 3662910
E-mail: Patrick.Dular at ulg.ac.be




More information about the getdp mailing list