Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I would like to generate a plot of CPU time vs number of iterations. For example, if I were to calculate the solution of a system of differential equations in state-space form using the summation of e^(A t) (or any series expansion for that matter):

A = {{1, 2}, {3, 4}}
sol=Sum[(MatrixPower[A, j] t^j)  /j!, {j, 0, 200}]

I tried:

Table[Timing[N[Sum[(MatrixPower[A, j] t^j)  /j!, {j, 0, i}]]], {i, 0, 

but this outputs the solution of the summation along with the time. I only require the cpu time for each individual iteration and the iteration number. Can someone point me in the right direction here?

share|improve this question

marked as duplicate by Michael E2, belisarius, m_goldberg, Sjoerd C. de Vries, rasher Jul 8 '14 at 6:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

It's very intriguing that you've managed the problem till this point but now you don't know how to plot it. –  belisarius Jul 8 '14 at 4:09
I never said I didn't know how to plot it, I asked how to plot the timing of each individual evaluation. But, thanks for not attempting to help nonetheless. –  gKirkland Jul 15 '14 at 0:45

1 Answer 1

up vote 1 down vote accepted

How about

Table[First@Timing[N[Sum[(MatrixPower[A, j] t^j)/j!, {j, 0, i}]]], {i, 0, 200}]

Mathematica graphics

If you want the iteration number side by side, just change the body of the Table to {i, First@...}.

share|improve this answer

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