MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Clean up code to run faster

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122450] Re: Clean up code to run faster
  • From: A Retey <awnl at gmx-topmail.de>
  • Date: Sat, 29 Oct 2011 07:08:51 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j7u4rb$t67$1@smc.vnet.net>

Hi,

> I am new to Mathematica and I have learned that it is a steep learning
> curve, I've spent a week trying to program an example problem from a
> heat transfer book.  I need it to solve for several hundred time steps
> and my computer is only allowing me to do about 15 in an hour of
> solving.  How can I clean up my code and what are some general tips
> that you can give me for the future when I need to do more hard core
> iteration problems and stuff?  PS, I'm a mechanical engineer so I'm
> not very good at understanding how Mathematica thinks in computer
> language (anything is helpful).

I think you got some hints about how to speed up your actual 
calculation. I just wanted to make sure you understand that there is 
actually no need to solve such a simple problem with such a low level 
approach: Mathematica can solve many partial differential equations out 
of the box. Only if you are taking advantage of those feature you will 
find Mathematica to be a powerful tool once you have learned how to use 
it. Here is an example which solves a 1d heat transfer problem with 
NDSolve, straight from the documentation of NDSolve:

NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0,
   u[t, 0] == Sin[t], u[t, 5] == 0}, u, {t, 0, 10}, {x, 0, 5}]

Plot3D[Evaluate[u[t, x] /. %], {t, 0, 10}, {x, 0, 5},
  PlotRange -> All]

Of course you would have to adopt the boundary condition to your case. 
If you are just using this as an example for learning Mathematica, you 
might want to use such a solution to check your results...

hth,

albert



  • Prev by Date: Re: Strings with different Styles in a Grid
  • Next by Date: Re: Coin Toss Sim
  • Previous by thread: Re: Clean up code to run faster
  • Next by thread: a bug in Integrate