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
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.
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
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.