Re: Changing names of variables in a loop

• To: mathgroup at smc.vnet.net
• Subject: [mg92192] Re: [mg92166] Changing names of variables in a loop
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 22 Sep 2008 07:23:41 -0400 (EDT)
• Reply-to: hanlonr at cox.net

a1 = 1; a2 = 2; a3 = 3;

Sum[ToExpression["a" <> ToString[n]], {n, 3}]

6

Simpler to just use the form a vice a1

a = 1; a = 2; a = 3;

Sum[a[n], {n, 3}]

6

Bob Hanlon

---- kazik.lakomy at gmail.com wrote:

=============
Hi,
do you know maybe is there a possibility to change a name of a
variable in a loop? I'm not exactly sure how to explain it, so maybe
instead of my words I paste a basic example that express my query:

a1 = 1; a2 = 2; a3 = 3;
func[g_] := g;
Summ = 0;

For[i = 1, i <= 3, i += 1,
Summa += func[ai]]

So something like this... I have tried to deal with this like with
strings and have put func[a<>"i"] but it didn't work (quite logic).
The general problem is much more complicated, this is only a part of
it, so please do not suggest me how can I sum up three numbers, this I
believe I know :) I would very appreciate any hints,
Best regards,
Kazik

--

Bob Hanlon

• Prev by Date: Re: Using FindRoot or interpolation function with symbolic argument
• Next by Date: Re: labeling axes in a ContourPlot
• Previous by thread: Re: Changing names of variables in a loop
• Next by thread: Re: Changing names of variables in a loop
{"ft_lang_label":"__label__en","ft_lang_prob":0.8933686,"math_prob":0.83687884,"size":1150,"snap":"2019-43-2019-47","text_gpt3_token_len":384,"char_repetition_ratio":0.08900524,"word_repetition_ratio":0.07111111,"special_character_ratio":0.3721739,"punctuation_ratio":0.18050541,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98796356,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-18T20:12:09Z\",\"WARC-Record-ID\":\"<urn:uuid:c54c049f-5ef0-4049-9431-a758475866b0>\",\"Content-Length\":\"44733\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a192e980-f868-4e32-864e-fb6d30974dbc>\",\"WARC-Concurrent-To\":\"<urn:uuid:e4f69d73-b971-4870-8206-c6eada9a9cca>\",\"WARC-IP-Address\":\"140.177.205.73\",\"WARC-Target-URI\":\"http://forums.wolfram.com/mathgroup/archive/2008/Sep/msg00507.html\",\"WARC-Payload-Digest\":\"sha1:WQ5XOIY5APOIS5OQYN6DJWNY7JITBVXM\",\"WARC-Block-Digest\":\"sha1:GDP3DTPJZY5VFLPC67TM6JJP2YMHXFQ3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570986684425.36_warc_CC-MAIN-20191018181458-20191018204958-00228.warc.gz\"}"}