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

How to create a database in Mathematica

  1. Feb 1, 2012 #1
    Hi All,

    I have to solve a system of non-linear equations for a wide range of parameter space. I'm using FindRoot which is sensitive to initial conditions so I have to do it by hand and by trial and error and plotting, rather than putting the equations in a loop or in a table.

    So what I want to do is create a databse or a Matrix with a fixed number of columns but variable number of rows so I can keep appending it with new results as and when I solve for them.

    I've looked at a few mathematica books and their online reference but they only teach me how to create a table or a matrix already filled with some numbers or text or functions. What I want to create is a blank variable of the matrix type to which I can keep adding more and more rows (or records) and my database develops to add my solutions for the varying parameter space. Can someone please tell me how I can create a matrix type variable, declare it to be a matrix and then at my own leisure append rows or records to it.

    Thanks a lot
    N
     
  2. jcsd
  3. Feb 4, 2012 #2
    Create an empty list for your database.
    Then construct a new row for the database, perhaps using Solve or other methods.
    Join your new row with your database.
    Use [[]] to extract elements from your database.

    In[30]:= database={};
    In[31:= newrow={1,2,5,4,3,7,1,1,1,1};
    In[32]:= database=Join[database,{newrow}]
    Out[32]= {{1,2,5,4,3,7,1,1,1,1}}

    In[33]:= newerrow={1,2,3,4,5,6,7,8,9,10};
    In[34]:= database=Join[database,{newerrow}]
    Out[34]= {{1,2,5,4,3,7,1,1,1,1},{1,2,3,4,5,6,7,8,9,10}}

    In[35]:= database[[2,9]]
    Out[35]= 9
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook