Hi,(adsbygoogle = window.adsbygoogle || []).push({});

I want to use a module to repeatedly calculate a parameter in NDSolve, but I seem to be having trouble. Here is a simplified version of what I'm doing. In this example, I want to use the difference between v1 and v2 at a given timepoint to calculate the connection between v1 and v2 for the next timepoint.

I am getting the error "NDSolve::ndnum: Encountered non-numerical value for a derivative at s == 0.`." but as far as I can see, everything is defined in the module. If I replace Tau with a constant, I get no errors, which leads me to think it must be something to do with the way I am sampling the value of v1 and v2 from the main NDSolve loop?

Thanks for your help

---

connection[vdiff_, t_] :=

Module[{deltav = vdiff, Tau, con},

Tau = 120 + 7434.49/(1 + 0.00262985 (deltav[[1]])^2);

con = NDSolve[{g' == (1/Tau)*(3 - g), g[0] == 1},

g, {s, 0, T}];

g[t] /. con]

A = 3;

\[Epsilon] = 0.2;

\[Alpha] = 3;

\[Gamma] = 0.05;

v0 = 0.4;

w0 = 0.4;

T = 25;

initial =

Solve[wi == A*vi*(vi - \[Alpha])*(1 - vi) - w0 &&

wi == (vi - v0)/\[Gamma], {vi, wi}, Reals];

fitz = NDSolve[{v1'[

t] == ((A*v1[t]*(v1[t] - \[Alpha])*(1 - v1[t]) - w1[t] -

w0)/\[Epsilon])

+ (connection[v1[t] - v2[t], t]*(v2[t] - v1[t])),

v2'[t] == ((A*v2[t]*(v2[t] - \[Alpha])*(1 - v2[t]) - w2[t] -

w0)/\[Epsilon])

+ (connection[v2[t] - v1[t], t]*(v1[t] - v2[t])),

w1'[t] == v1[t] - \[Gamma]*w1[t] - v0,

w2'[t] == v2[t] - \[Gamma]*w2[t] - v0,

v1[0] == kick + vi /. initial,

v2[0] == vi /. initial,

w1[0] == wi /. initial,

w2[0] == wi /. initial},

{v1, v2, w1, w2}, {t, 0, T}];

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Mathematica calling module from NDSolve

Loading...

Similar Threads for Mathematica calling module |
---|

Mathematica Storing Mathematica output |

Mathematica Mathematica to MATLAB |

Mathematica Cannot do the integral of the Hyper-geometric function? |

Mathematica Cannot Plot This Function in Mathematica |

Mathematica While Loop in Mathematica |

**Physics Forums | Science Articles, Homework Help, Discussion**