# Help to solve the equation with RungeKutta method [closed]

I need to solve this equation.

v'[t] + v[t] == 1/(1 + Exp[-v[t]])


I tried to solve it using RungeKutta method described in Wolfram tutorial(http://reference.wolfram.com/mathematica/tutorial/NDSolvePlugIns.html#51030643)

But, I get some errors. I was wondering if anyone can help me to correct the error. I am still trying to figure it out. Appreciate any help. Thanks.

 CRK4[]["Step"[rhs_, h_, t_, x_, xp_]] := Module[{k0, k1, k2, k3},
k0 = h xp;
k1 = h rhs[t + h/2, x + k0/2];
k2 = h rhs[t + h/2, x + k1/2];
k3 = h rhs[t + h, x + k2];
(k0 + 2 k1 + 2 k2 + k3)/6]
CRK4[___]["StepInput"] = {"F"["T", "X"], "H", "T", "X", "XP"};
CRK4[___]["StepOutput"] = "XI";

CRK4[___]["DifferenceOrder"] := 4

CRK4[___]["StepMode"] := Fixed
a = NDSolve[{v'[t] + v[t] == 1/(1 + Exp[-v[t]]), v[0] == 1},
v, {t, 0, 100}, Method -> CRK4]


But, It gives an error. I actually want to plot a graph of V vs t.

-

## closed as off-topic by m_goldberg, bobthechemist, Michael E2, belisarius, Verbeia♦Apr 13 at 4:49

• The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

@RunnyKine Thanks. I already saw it.But, I couldn't understand how to use it. I tried and ended up with some errors. I was not able to get any solutions. Could you please tell me, how to get a solution and plot the graph using solutions. –  TMH Apr 11 at 20:49
Your code works as expected on my system: V9.0.1 running on OS X. I get no errors and a very reasonable plot. –  m_goldberg Apr 12 at 9:51
This question appears to be off-topic because the problem the user claims to be experiencing can not be reproduced. –  m_goldberg Apr 12 at 9:53
@m_goldberg I don't know why does it result an error only for me. –  TMH Apr 12 at 14:52
If I have a question like this, from whom should I ask. I am student and my adviser doesn't use Mathematica too. This is a very simple thing for experts like you all. So, it will not waste/spend your much time to reply a question like this.Please be kind enough before you drop a question down. May be someone else has experienced the same thing and he/she could reply me. I am still getting the error. –  TMH Apr 13 at 15:41

The code you posted did not produce errors for me, try running on a fresh kernel.

To plot the solution:

Plot[v[t] /. First[a], {t, 0, 100}]


-
I tried several times. But, I am still getting this error message. "NDSolve::bdstep: The Step function for Method -> CRK4 returned {0.}, which is not an acceptable form. >>" Didn't you get this? –  TMH Apr 12 at 1:08
I copied the code straight from your post. It seems to have evaluated without error for me.. –  dstahr Apr 12 at 1:34
I was not able to use the above code so far. So, I used the below code to use RungeKutta method. Could you please run it and let me know if it works in your computer without any error. –  TMH Apr 15 at 15:01
Runge[a0_, b0_, \[Alpha]_, m0_] := Module[{a = a0, b = b0, j, m = m0}, h = (b - a)/m; Y = T = Table[0, {m + 1}]; T[[1]] = a; Y[[1]] = \[Alpha]; For[j = 1, j <= m, j++, k1 = h f[T[[j]], Y[[j]]]; k2 = h f[T[[j]] + h/2, Y[[j]] + k1/2]; k3 = h f[T[[j]] + h/2, Y[[j]] + k2/2]; k4 = h f[T[[j]] + h, Y[[j]] + k3]; Y[[j + 1]] = Y[[j]] + 1/6 (k1 + 2 k2 + 2 k3 + k4); T[[j + 1]] = a + h j;]; Return[Transpose[{T, Y}]]] f[t_, y_] = -y + 1/(1 + Exp[-y]); points4 = Runge[0, 1, 1, 10]; Needs["GraphicsColors"]; ListPlot[points4, Joined -> True, PlotRange -> All, PlotStyle -> Orange] –  TMH Apr 15 at 15:03
I am getting errors with this code too. But, this code works with other equations. So, I am wondering if I could use RungeKutta method in Mathematica to solve equations with exponential. Appreciate your help. –  TMH Apr 15 at 15:07