Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8579

NDSolve slow when using generic function definition

From Panayiotis Georgiou <ps.georgiou@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject NDSolve slow when using generic function definition
Date 2012-02-17 11:24 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jhlddv$or1$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hello,

I am using NDSolve to solve a simple 1st order ODE. The problem I have
is that when I solve the function with predefined parameters it runs
extremely fast. However, if I try to do the same but by defining a
generic function it is extremely slow. I have tried placing the
evaluate at various places but still no luck.

To be more specific, when solving this for example:

sol = NDSolve[{z'[t] == \[Alpha]*fmod2[z[t], 2, 0.5, k, 1, d]*
      I1[t], z[0] == 0.1}, z, {t, 0, 1/f0}, MaxStepSize -> 0.0001,
   AccuracyGoal -> 6, PrecisionGoal -> 5];

pp4 = Plot[{Evaluate[z[t] /. sol]}, {t, 0, 1/f0}, PlotRange -> All,
  AxesOrigin -> {0, 0},
  GridLines -> {{{0.5, Dashed}, {max[n1], Dashed}}, None}]

It runs almost instantly. But then if I do the following:

Zt[t_, n_, m_, j_, d_] :=
  z[t] /. NDSolve[{z'[t3] == \[Alpha]*fmod2[z[t3], n, m, K[n], j, d]*
       I1[t3], z[0] == z0}, z, {t3, 0, 1/f0}, MaxStepSize -> 0.0001,
    AccuracyGoal -> 6, PrecisionGoal -> 5];

pp4 = Plot[{Evaluate[Zt[t, 2, 0.5, 1, d]]}, {t, 0, 1/f0},
  PlotRange -> All, AxesOrigin -> {0, 0},
  GridLines -> {{{0.5, Dashed}, {max[n1], Dashed}}, None}]

It takes about 5 minutes to evaluate and plot. I have tried enclosing
in Evaluate[] various parts of the function definition but it is still
extremely slow.

Do you have any idea why there is this speed difference between the
two approaches?

Thanks for your help.




Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

NDSolve slow when using generic function definition Panayiotis Georgiou <ps.georgiou@gmail.com> - 2012-02-17 11:24 +0000

csiph-web