Message Boards Message Boards

0
|
3035 Views
|
12 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Combine the output of two generated tables and sort them in order?

Posted 4 years ago

I've been trying unsuccessfully to combine the numerical output of two tables and then have them arranged in descending order. I have two expressions thus the need for two tables, but I can't find any examples of what I'm trying to do and I don't know if two tables can even be combined let alone sort all of the numbers from the two columns from greatest to least. I tried to use Union and Sort on the tables directly, that doesn't work, I also put my each of the Tables inside a list command and then tried Union and Sort and that didn't work either. Right now the Tables are arranged in columns, and both tables are created using one command (when I was using two they weren't aligned). Here's what I got

n = 35;
a = (x*2) + 3;
b = (a + Sqrt[(a)^2 - (n*4)])/4;
c = (x*2) - 9;
d = ((c) + Sqrt[(c)^2 + (n*4)])/4;
e = Column[Table[{b, d}, {x, number, 5, -1}], Frame -> All]
POSTED BY: Chris Agee
12 Replies
Posted 4 years ago

If I do this

n = 35;
a = (x*2) + 3;
b = (a + Sqrt[(a)^2 - (n*4)])/4;
c = (x*2) - 9;
d = ((c) + Sqrt[(c)^2 + (n*4)])/4;
e = Column[N[Table[{b, d}, {x, n, 5, -1}]], Frame -> All]

That doesn't change any of your code except adding N so I can see decimal values for all your numbers... then Mathematica displays

{{36.258678463452, 30.784236382905984},
 {35.25178562318713, 29.79368638333038}, 
 {34.24448439935734, 28.803779577827882},
 {33.236737093797544, 27.814583179035203}, 
 {32.228501181274794, 26.826173982385463},
 {31.219728504404983, 25.838640112708426}, 
 {30.21036430037718, 24.85208316112856},
 {29.200346016618425, 23.86662081605263}, 
 {28.189601859450647, 22.88239012413184},
 {27.178049001995785, 21.89955156048888}, 
 {26.16559135308949, 20.918294146675933},
 {25.15211675481246, 19.938841936157417}, 
 {24.137493427968742, 18.961462299777516},
 {23.12156541554416, 17.986476600955584}, 
 {22.104146673046206, 17.01427407147905},
 {21.085013304297192, 16.04533001151853}, 
 {20.06389321319526, 15.080229881682913},
 {19.040452088031024, 14.119701486491838}, 
 {18.01427407147905, 13.164658342969666},
 {16.9848345460003, 12.216258578188782}, 
 {15.95146090037468, 11.275985396596976},
 {14.913274390947201, 10.345757321399848}, 
 {13.869101147436863, 9.428078794301996},
 {12.817330549755798, 8.5262432936357}, 
 {11.75567888638631, 7.644598957811737},
 {10.680770730829005, 6.788873605350878}, 
 {9.587337893224369, 5.966517186829627},
 {8.466517186829627, 5.18693177121688}, 
 {7.3016389039334255, 4.461308144666282},
 {6.054886114323222, 3.8016389039334255}, 
 {4.596291201783626, 3.218585521759479}}

That looks like your numbers are already in descending order in each column.

Is that what you wanted? Or do you need some other ordering?

If it would be easier for you to create two tables and then combine them then try

t1=Table[i^2,{i,1,3}];
t2=Table[2i+1,{i,1,3}];
Column[Transpose[{t1,t2}],Frame->All]

and you should see two nicely formatted columns of numbers.

If there is something else you need and you can explain so that I can understand then perhaps I can find a way to modify this.

POSTED BY: Bill Nelson
Posted 4 years ago

I want to combine both columns into one and then sort the numbers from the greatest to the smallest.

POSTED BY: Chris Agee
Posted 4 years ago

That helped me understand

n = 35;
a = (x*2) + 3;
b = (a + Sqrt[(a)^2 - (n*4)])/4;
c = (x*2) - 9;
d = ((c) + Sqrt[(c)^2 + (n*4)])/4;
e = Column[Reverse[Sort[Flatten[Table[{b, d}, {x, n, 5, -1}]]]],Frame->All]
POSTED BY: Bill Nelson
Posted 4 years ago

Thank you this is what I was looking for! Now I just have to figure out how to remove any duplicate numbers.

POSTED BY: Chris Agee
Posted 4 years ago
Posted 4 years ago

Tried union doesn't work, right now I'm looking into deleting specific rows, but all it does is delte the entire table.

POSTED BY: Chris Agee
Posted 4 years ago

If you can show the exact code you are using so that I can exactly reproduce your results, and you can describe exactly what the duplicate rows are, so I can identify them here, then I will see if I can find what mistake I made and we can try to get this fixed for you.

POSTED BY: Bill Nelson
Posted 4 years ago

I figured out how to do it, it’s a little convoluted, but it works now.

POSTED BY: Chris Agee
Posted 4 years ago

One last question, do you know how a second column to the first?

POSTED BY: Chris Agee
Posted 4 years ago

Hi Chris,

What do you mean by

do you know how a second column to the first

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

The question should have been “do you know how to add a second column to the first one?

POSTED BY: Chris Agee
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract