Re: Table Format Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg98399] Re: Table Format Problem
- From: dh <dh at metrohm.com>
- Date: Thu, 9 Apr 2009 05:52:01 -0400 (EDT)
- References: <grhp6r$mh1$1@smc.vnet.net>
Hi, to format your data, try the following: tab = Table[ Flatten@Table[{R1[t], P1[t]} /. sol[J], {J, 1, 5, 1}], {t, 100, T, 1}]; TableForm[tab, TableHeadings -> {Range[100, T], Flatten@Table[{R1[J], P1[J]}, {J, 1, 5}]}] Daniel Solver wrote: > Hello, > > I would like to export the results of an NDSolve simulation but I can > not seem to figure out how to export my data in the format I want. > Here is a simplified version of my code. I have two variables: R1 and > P1. I am solving the system from t = 100 to 110 for values of J = 1 to > 5. I want my data to be in the following format: > Each column is a solution to a variable for a given time (time are the > rows). I would have 10 columns (R1[J=1], P1[J=1],R1[J=2],P1[J=2]...R1 > [J=5],P1[J=5]) and 11 rows (one for each time step). The closest I > could get was having 2 columns (R1, P1) with the rows being solutions > for J=1, then J=2, etc. > Here is my code: > > a1=1; > d1=.3; > l1=.15; > T=110; > > dR1=J-l1*R1[t]-a1*R1[t]*P1[t]; > dP1=a1*R1[t]*P1[t]-d1*P1[t]; > > Flatten[Map[({R1[110],(P1[110])}/.#)&,Table[sol[J]=NDSolve[{R1'[t] > ==dR1,P1'[t]==dP1,R1[0]==1,P1[0]==1},{R1,P1},{t,100,T},MaxSteps- >> 100000],{J,1,5,1}]],1]//Transpose; > > A=Flatten[Table[Evaluate[({R1[t],P1[t]}/.sol[J]),{J,1,5,1}],{t,100,T, > 1}],2]; > > Export["Data.csv",A]; > > I appreciate any help you can provide! > > Cheers, > Shawn >