Mathematica How to create a database in Mathematica

Click For Summary
To create a dynamic database in Mathematica, start by initializing an empty list for your database. You can then construct new rows using methods like Solve, and append these rows to your database using the Join function. For example, you can create a new row and add it to the database with commands like database = Join[database, {newrow}]. This allows for a flexible structure where you can continuously add records as you solve for different parameters. The process enables efficient management of results from non-linear equations without needing a pre-filled matrix.
NRedacted
Messages
7
Reaction score
0
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
 
Physics news on Phys.org
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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
10K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K