PDA

View Full Version : How to create a database in Mathematica


NRedacted
Feb1-12, 09:56 PM
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

Bill Simpson
Feb4-12, 06:35 PM
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