Re: export differential equation solution obtained
- To: mathgroup at smc.vnet.net
- Subject: [mg106346] Re: [mg106326] export differential equation solution obtained
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 10 Jan 2010 03:28:03 -0500 (EST)
- Reply-to: hanlonr at cox.net
In your first equation (after "=" is replaced by "=="), you used p[t] in both terms. I changed the second to n[t]
sol3 = NDSolve[{
p'[t] == -0.0491*p[t] - 0.0089*n[t],
n'[t] == 0.0491*p[t] + (0.0491 - 0.0089)*n[t],
p[0] == 25000, n[0] == 0},
{p, n}, {t, 0, 100}][[1]];
Plot[Evaluate[n[t] + p[t] /. sol3], {t, 0, 100}]
Generate an array of the data that you want
data = Join[{{"t", "n[t]", "p[t]", "n[t] + p[t]"}},
Table[{t, n[t], p[t], n[t] + p[t]},
{t, 0, 100, 5}] /. sol3];
Export["newdata.csv", data];
Bob Hanlon
---- Yun Zhao <yun.m.zhao at gmail.com> wrote:
=============
Hi everyone,
I would like to know if there is a way to export differential equation
solution obtained through Mathematica to microsoft excel. There are several
data processing things that I want to know, that simply plotting the
solution in Mathematica won't suffice.
I have a system of differential equations like so:
sol3=NDSolve[{p'[t]=-0.0491*p[t]-0.0089*p[t],n'[t]=0.0491*p[t]+(0.0491-0.0089)*n[t],p[0]=25000,n[0]=0},{p,n},{t,0,100}]
When I plotted it in Mathematica using this code:
Plot[Evaluate[{n[t]+p[t]}/.First[sol3]],{t,0,100}]
I get a exponential increasing function plotting number vs. time.
What I want is the values of both the time vector and number vector, and I
want to copy and paste them into two columns in microsoft excel.
I tried using:
Export["newdata.dat", Evaluate[{n[t]+p[t]}/.First[sol3]]
But this gives me a .dat file with the time and number vectors all scrambled
up.
My question is:
(1) is there a better way to tell Mathematica what I want to export, because
I don't think Evaluate[{n[t]+p[t]}/.First[sol3] is the correct term to
convey what I want
(2) How do I properly export differential equation solutions that I can
graph but not display in Mathematica, to spreadsheets software like
Microsoft Excel?
Thank you all very much.