Mathematica Mathematica calling module from NDSolve

AI Thread Summary
The discussion revolves around using a module in Mathematica to calculate parameters for NDSolve, specifically addressing an error encountered when trying to derive values from a dynamic connection between two variables, v1 and v2. The user is experiencing a "non-numerical value for a derivative" error, which seems to stem from the way values are being sampled within the NDSolve loop. It is suggested that the variable Tau, which is dependent on v1 and v2, is not being treated as a constant, leading to the failure of NDSolve. The recommendation is to ensure that the connection module receives fixed numerical values instead of dynamic expressions to resolve the issue. This highlights the importance of defining all parameters as constants when using NDSolve in Mathematica.
musicgirl
Messages
12
Reaction score
0
Hi,

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 news on Phys.org
NDSolve expects everything, except the function you are solving for and the independent variable, to have been assigned a fixed numeric value.

When I insert
Print["Tau=", Tau];
just after your initialization of Tau in your connection[] module it prints
Tau=120+7434.49/(1+0.00262985 v1[t]^2)
and then your NDSolve is going to fail.

That is why your connection[] NDSolve is throwing an error and then your replacement is throwing an error and then your outer NDSolve is throwing an error.

See if you can find a way to pass your connection constant Real values and see what happens.
 

Similar threads

Replies
3
Views
10K
Replies
8
Views
3K
Replies
6
Views
2K
Replies
3
Views
5K
Replies
2
Views
1K
Replies
2
Views
6K
Replies
1
Views
4K
Replies
1
Views
4K
Replies
4
Views
5K
Back
Top