Re: Looking to time how long a command takes in mathematica 6 tia
- To: mathgroup at smc.vnet.net
- Subject: [mg97070] Re: Looking to time how long a command takes in mathematica 6 tia
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Wed, 4 Mar 2009 07:14:08 -0500 (EST)
Hi, Aloha , I think, you should write "<= ", rather than "=" in the definition of your piecewise function. Have a look at this: In[16]:= f[x_] := Piecewise[{{4.*x^2 - 4.*x, 0 <= x <= 1}, {-2*x^2 + 8*x - 6, 1 <= x <= 3}, {x^2 - 10*x + 21, 3 <= x <= 7}, {-1/2*x^2 + 11*x - 105/2, 7 <= x <= 15}, {.5714285714*x^2 - 21.14285714*x + 188.5714286, 15 <= x <= 22}, {-.8*x^2 + 39.2*x - 475.2, 22 <= x <= 27}}] In[20]:= Timing[Play[f[x], {x, 0, 27}]] Out[20]= {0.031, (Sound[ SampledSoundFunction[ CompiledFunction[{Blank[Integer]}, {{2, 0, 0}, {3, 0, 1}}, {0, 1, 3, 0, 0}, {{1, 5}, {8, 0., 0}, {8, 0.000125, 1}, {15, 1, 0, 2}, {21, 1, 2, 1}, {18, 0, 1, 0}, { 54, Function[{ Play`Time5}, $CellContext`f[$CellContext`x]], {$CellContext`x, 3, 0, 0, Block}, 2, 0, 0, 3, 0, 1}, { 8, -0.5000937551520472, 2}, {18, 1, 2, 1}, { 8, 0.13333620140328437`, 2}, {21, 1, 2, 1}, {2}}, Function[{Play`Time5}, Block[{$CellContext`x = 0. + 0.000125 Play`Time5}, \ ($CellContext`f[$CellContext`x] - 0.5000937551520472) 0.13333620140328437`]], Evaluate], 216000, 8000]])} Have a success, Alexei Grettings All I'm running this command Play[Piecewise[{{4.000000000*x^2 - 4.000000000*x, 0 = x <= 1}, {-2*x^2 + 8*x - 6, 1 = x <= 3}, {x^2 - 10*x + 21, 3 = x <= 7}, {-1/2*x^2 + 11*x - 105/2, 7 = x <= 15}, {.5714285714*x^2 - 21.14285714*x + 188.5714286, 15 = x <= 22}, {-.8000000000*x^2 + 39.20000000*x - 475.2000000, 22 = x <= 27}}], {x, 0, 27}] and it's taking extremely long and would like to find out how long it takes to run this line. Also if anyone has a more efficient way of using this command please let me know. I'm just trying to output the wave file to an audio file. Aloha sal2 -- Alexei Boulbitch, Dr., Habil. Senior Scientist IEE S.A. ZAE Weiergewan 11, rue Edmond Reuter L-5326 Contern Luxembourg Phone: +352 2454 2566 Fax: +352 2454 3566 Website: www.iee.lu This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.