Message Boards Message Boards

0
|
9909 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to write NDSolve results into a table without brackets?

Posted 9 years ago

Hello,

I want to write the results which I got out of NDSolve function into a table. Once I've managed that I'll write them into a file for further processing. Unfortunately, the results seem to be written within brackets in the following form: {{value}} My aim is to have the values written without the brackets.

The code is as follows, whereas x[t] is an InterpolatingFunction as a result from NDSolve:

q[t_] = Exp[-t/50];

s = NDSolve[{x'[t] == x[t]*(z[t] - q[t]) - x[t], z'[t] == -z[t]*x[t], x[0] == x0, z[0] == z0}, {z[t], 
   x[t]}, {t, 0, 5000}]

data = Table[{t, Evaluate[{x[t]} /. s]}, {t, 0, 2000, 0.5}];

Export["data_table.csv", data];

Best regards

POSTED BY: Chris Smith
3 Replies
Posted 9 years ago

NDSolve is Numerical DSolve. That means everything you aren't solving for must have been previously assigned a numeric value.

Insert something like

x0 = 4; z0 = 6;

before your NDSolve and it should work much better for you.

Then you might have a few extra layers of {} that csv might object to, but it looks like you can figure those out for yourself.

POSTED BY: Bill Simpson
Posted 9 years ago

Hello Bill, thanks for the fast reply.

Basically the brackets {} are my problem. I have problems figuring out how to get rid of them using mathematica. Any idea?

Best regards

POSTED BY: Chris Smith
Posted 9 years ago

Try this

data = Table[Flatten[{t, Evaluate[{x[t]} /. s]}], {t, 0, 2000, 0.5}];

That, with telling Export to use csv, seems to be enough to get you where you need to be.

POSTED BY: Bill Simpson
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