Re: How can I acceralate calcution by improving coding?
- To: mathgroup at smc.vnet.net
- Subject: [mg30345] Re: [mg30314] How can I acceralate calcution by improving coding?
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Sat, 11 Aug 2001 03:40:05 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
One thing that will make some improvement is wrapping Evaluate around your your function inside Plot3D. Here is what I get running the preview version of Mathematica 4.1 for Mac OS X on a 400 mghz PowerBook G4: Timing[Plot3D[u[r, t], {t, 0, 2}, {r, a, b}, PlotRange -> {-1, 1}, AxesLabel -> {" t sec", " r m", "u K "}, FaceGrids -> {{0, -1, 0}, {1, 0, 0}, {0, 1, 0}, {-1, 0, 0}}, PlotPoints -> 50]] {Graphic} {338.16 Second,SurfaceGraphics} and Timing[Plot3D[Evaluate[u[r, t]], {t, 0, 2}, {r, a, b}, PlotRange -> {-1, 1}, AxesLabel -> {" t sec", " r m", "u K "}, FaceGrids -> {{0, -1, 0}, {1, 0, 0}, {0, 1, 0}, {-1, 0, 0}}, PlotPoints -> 50]] {Graphic} {252.77 Second Second, SurfaceGraphics} Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > Hello, > > I want to accelerate calculation speed of a function u1[r, t], which > is a > transient temperature distribution of a hollow cylinder with inner/outer > radii of a and b, respectively. > > (* u is in an asymptotic form using 0 th order Bessel function of 1st > and > 2nd kind. > The eigenvalue rho is a root of the f[\Rho]==0. *) > > f[\[Rho]_] = (\[Rho]*BesselJ[1, \[Rho]*a] + \[Alpha]0*BesselJ[0, > \[Rho]*a])* > BesselY[1, \[Rho]*b] - (\[Rho]*BesselY[1, \[Rho]*a] + > \[Alpha]0*BesselY[0, \[Rho]*a])* > BesselJ[1, \[Rho]*b]; > > (* The concrete values used for numerical evaluation are as follows. *) > > a = 0.005; b = 0.015;\[Kappa]= > 0.0130/3600;\[Alpha]0=10000000/10.9;\[Omega]= > 2\[Pi]; > > (* n th root \[Rho]n and constant \[Beta]n are obtained as follows *) > > nmax=96; > > ddn = Table[FindRoot[ f[d] == 0, {d, 100+(j-1) 314.2}, > MaxIterations->100],{j,1,nmax}]; > > Subscript[\[Rho], n_] := ddn[[n,1,2]]; > > Subscript[\[Beta], n_] := > BesselJ[1, Subscript[\[Rho], n]*b]/BesselY[1, Subscript[\[Rho], > n]*b]; > > (* Now, let's defined u[r,t] *) > > > Subscript[R, n_][r_] := BesselJ[0, Subscript[\[Rho], n]*r] - > Subscript[\[Beta], n]*BesselY[0, Subscript[\[Rho], n]*r]; > > u[r_, t_] = Sin[\[Omega]*t] + > Sum[((\[Omega]*(\[Kappa]*Subscript[\[Rho], n]^2* > (E^((-\[Kappa])*Subscript[\[Rho], n]^2*t) - > Cos[\[Omega]*t]) - \[Omega]*Sin[\[Omega]*t]))/ > ((\[Kappa]*Subscript[\[Rho], n]^2)^2 + \[Omega]^2))* > ((2*\[Alpha]0*a)/Subscript[\[Rho], n]^2)* > ((Subscript[R, n][a]*Subscript[R, n][r])/ > ((b*Subscript[R, n][b])^2 - > (1 + (\[Alpha]0/Subscript[\[Rho], n])^2)* > (a*Subscript[R, n][a])^2)), {n, 1, nmax}]; > > (* Can anyone help to accelarate calculation ? > The following Plot3D takes 180 sec on a Pentium III 800 MHz machine. > I tried to ues Module, but it did not contribute in speed up*) > > Timing[Plot3D[u[r, t], {t, 0, 2}, {r, a, b}, PlotRange -> {-1, 1}, > AxesLabel -> {" t sec", " r m", "u K "}, > FaceGrids -> {{0, -1, 0}, {1, 0, 0}, {0, 1, 0}, {-1, 0, 0}}, > PlotPoints -> 50]] > > -Toshi > > >