# How to pass Jacobian to IDA via NDSolve

According to the IDA manual, when solving DAEs, there is an option to supply $J = df/dx + c*df/dx'$ (where $d$ is for partial derivatives) to the IDA module. How can I do the same via NDSolve? I tried the following just to see what happens:

vars = { alphan0, alphan1, alphan2, alphan3, alphan4, alphan5..., zetas1 };

tvars = { alphan0[t], alphan1[t], alphan2[t], alphan3[t], alphan4[t], alphan5[t], ..., zetas1[t] };

tvarsp = D[tvars, t]; Jdae1 = D[dae1[[All, 1]], {tvars}] - D[dae1[[All, 2]], {tvars}]; Jdae2 = D[dae1[[All, 1]], {tvarsp}] - D[dae1[[All, 2]], {tvarsp}];

jfun[t_, x_, xp_, c_] := Module[{j, jj},
j = (Jdae1 /. tvars -> x) + c (Jdae2 /. tvarsp -> xp);
Function[# jj] /. jj -> j];

sol3 = First@
NDSolve[{dae1, ic}, vars, {t, 0, 10},
WorkingPrecision -> 25, AccuracyGoal -> 5, PrecisionGoal -> 5,
Method -> {
IDA,
"ImplicitSolver" -> {
"Newton",
"LinearSolveMethod" -> {"Dense", "Jacobian" -> jfun}
}
}
]


Mathematica did not generate any error messages, however I am certain I am not doing it correctly. Many thanks!

-
can supply the rest of the code? –  user21 Jul 9 '13 at 12:36