I search the forum and found a question about exporting interpolating functions to excel. Unfortunately, I can't use it to export the results to excel. This is the equation :

u = StateResponse[ssm, UnitStep[t] , {t, 0, 1},Method -> {"NDSolve", MaxSteps -> 1600000}]

and the answer is :


I would appreciate that someone can help me to export this equation to a excel file.


I think the solution to your problem is implicitly hidden in here as I mentioned in the comment.Lets take an example problem!

res = StateResponse[
StateSpaceModel[{{{-3, 3/2, -1}, {-2, 1, -2}, {-1, 3, -2}}, {{1,0}, {1, -1}, {1, 1}},
{{1, 0, -1}}, {{0, 0}}}, 
SamplingPeriod -> None,SystemsModelLabels -> None], {SquareWave[t], Sin[t]}, {t, 0, 20}];

Also assume that the following is a summation expression you are interested in.

exp = Total[res^2 RandomReal[1, {3}]]

0.977826 InterpolatingFunction[{{0.,20.}},<>][t]^2+0.455719 InterpolatingFunction[{{0.,20.}},<>][t]^2+0.943215 InterpolatingFunction[{{0.,20.}},<>][t]^2

Now we export the expression exp defined in terms of InterpolatingFunction to an Excel data file as below

fun[k_] := exp /. t -> k;
tval = Range[0, 20, .01]; (*How often you want to record the values*)
Export[FileNameJoin[{$UserDocumentsDirectory, "sol.xlsx"}],Transpose@{tval,fun/@tval}];

Now test if things are working fine. Left one is directly from Mathematica and the right one after importing from the excel file we generated above followed by a consecutive interpolation.

impfun = Interpolation[
First@Import[FileNameJoin[{$UserDocumentsDirectory, "sol.xlsx"}],"Data"]];
GraphicsRow[Plot[#[t], {t, 0, 20}, Frame -> True] & /@ {fun, impfun},ImageSize -> 600]

enter image description here

  • $\begingroup$ @ PlatoManiac : It works my friend!! I really appreciate you for it. $\endgroup$ – Shield Aug 28 '13 at 14:39
  • $\begingroup$ You are welcome. The trick if you are new with Mathematica is be persistent and do not loose hope quickly! $\endgroup$ – PlatoManiac Aug 28 '13 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.