Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica - automatically change function name in for loop

  1. Sep 24, 2010 #1
    Hi folks,

    i just want to call different functions which are solutions of set of rate equations from s= NDSolve in a loop to calculate something.

    For[k = 0, k < 27, k++,

    x[k] = N#[time] /. s;


    # is just an arbitrary sign. i just want to replace # with k so i call


    how do i do that ?
    i use mathematica 7

  2. jcsd
  3. Sep 24, 2010 #2


    User Avatar
    Gold Member

    ToExpression[StringJoin["N", ToString[k]]][time] /. s

    might work
  4. Sep 24, 2010 #3
    Are you are trying to fill a table with 27 results. If so then perhaps something like this.

    x[[k]]=ToExpression[StringJoin["N", ToString[k]]][time] /. s;

    which gives


    Are you are trying to define 27 "functions" x[0], x[1],...x[26] then something like this.


    which gives

    x[0] = N0[1],
    x[1] = N1[1],
    x[26] = N26[1]
    Last edited: Sep 24, 2010
  5. Sep 25, 2010 #4
    Do you even need a loop? can't it be done with table and map?
  6. Sep 27, 2010 #5
    thanks. that was exactly what i was looking for. it works
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Mathematica automatically change Date
Mathematica Cannot do the integral of the Hyper-geometric function? Mar 11, 2018
Mathematica Cannot Plot This Function in Mathematica Feb 26, 2018
Mathematica While Loop in Mathematica Feb 25, 2018
Mathematica Mathematica Real Part Feb 24, 2018
Matlab Simulink: designing a 2nd order sliding controller Jul 5, 2017