Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8355101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:45:41+00:00 2026-06-09T09:45:41+00:00

I want to create multiple variables with iterated names in Mathematica, something like this:

  • 0

I want to create multiple variables with iterated names in Mathematica, something like this:

Do["f" <> ToString[i] = i*2, {i, 1, 20}]

where I get f1=2, f2=4, f3=6, … and so on.

I the error:

Set::write: Tag StringJoin in f<>1 is Protected. >>

Any help would be great. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:45:43+00:00Added an answer on June 9, 2026 at 9:45 am

    To achieve this you need to evaluate the "f" <> ToString[i] expression before Set (=) sees it, or you attempt to assign to an object with head StringJoin, just as the error message tries to tell you. Further, you cannot make an assignment to a string, so you need to convert it to a Symbol, using (surprise) Symbol. One method is to use Evaluate:

    Do[Evaluate[Symbol["f" <> ToString[i]]] = i*2, {i, 1, 20}]
    
    {f1, f2, f17}
    

    {2, 4, 34}

    This however is not usually a good course of action with Mathematica. For example, if any of these symbols already exist and have a value assigned the operation will fail. One can get around this with more effort as seen in the answers to How to Block Symbols without evaluating them? (or more specifically in my answer here) but again, it is not usually a good course of action.

    The normal method is to use indexed objects as PrinceBilliard shows.

    Please see this question, its answers, and the four related questions linked in the comment below it for more on this topic in general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom field with multiple values like it may store
Hi in my mobile application I want to create multiple variables and want to
I want to write a JS library and handle it like this: var c1
i want create multiple search where statement $where_search is a multiple condition from post
I want to create multiple versions of print-friendly pages from a single page. I
I`v come across a need where I want to create multiple list items from
I have an XML file (on the left) and I want to create multiple
hey i want to be able to create multiple shapes and store them perhaps
I want to create a single video file from multiple video files (parts). I
I want to create an array that has multiple index and in each index

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.