# What is wrong with my code? [closed]

What is wrong with my code below

f1[ar_, cj_, mj_, tj_, kj_, s_, w_] :=
ar*J[t] + cj*R[t] + mj*J[t] - tj*R[t] - kj*J[t] + s*R[t]*J[t] + w*J[t]*R[t];
g1[aj_, cr_, mr_, tr_, kr_, s_, w_] :=
aj*R[t] + cr*J[t] + mr*R[t] - tr*J[t] - kr*R[t] - s*R[t]*J[t] - w*J[t]*R[t];

splot = StreamPlot[{f[1, 1, 0, 0, 1, 1], g[1, 1, 0, 0, 1, 1]}, {J, -4,4},{R, -4, 4}];
Manipulate[Show[splot,ParametricPlot[Evaluate[First[{x[t], y[t]} /.
NDSolve[{J'[t] == f1[1, 1, 0, 0, 1, 1], R'[t] == g1[1, 1, 0, 0, 1, 1],
Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]]], {t, 0,T}, PlotStyle -> Red]],
{{T, 10}, 1, 100}, {{point, {1, 0}}, Locator}, SaveDefinitions -> True]


I am getting the error ConstantArray::ilsmn: Single or list of non-negative machine-sized integers expected at position 2 of ConstantArray[{J,R},-\[Infinity]].

• This is not a free debugging service... Dec 5, 2018 at 22:27
• I don't really understand the error in my code, that is why I am asking it here. I thought this was one of the purpose of the site. If you can help, or point me to the right direction, it will be much appreciated. Dec 5, 2018 at 22:29
• It would have be easy for you to find out that Manipulate and ParametricPlot. The error occurs already when executing NDSolve[{J'[t] == f1[1, 1, 0, 0, 1, 1], R'[t] == g1[1, 1, 0, 0, 1, 1], Thread[{x[0], y[0]} == point]}, {x, y}, {t, 0, T}]. You try to solve for x and y but the equations are in terms of J and R. And you defined f1 and g1 as functions in seven variables but you call them only with six variables. NDSolve[{ J'[t] == f1[1, 1, 0, 0, 1, 1, 1], R'[t] == g1[1, 1, 0, 0, 1, 1, 1], Thread[{J[0], R[0]} == point] }, {J, R}, {t, 0, T}] seems to work. Dec 5, 2018 at 22:32
• @HenrikSchumacher Thanks for the reply but your code is still giving errors. I don't really understand the errors Dec 5, 2018 at 22:41
• @DMH16 I think the title of your post should at least attempt to describe the problem you are facing. Presently 95 % of the posts in this SE could be called what is wrong with my code... Dec 6, 2018 at 1:19

after fixing a lot of typos, the code works

f1[ar_, cj_, mj_, tj_, kj_, s_, w_, R_, J_] :=
ar*J + cj*R + mj*J - tj*R - kj*J + s*R*J + w*J*R;
g1[aj_, cr_, mr_, tr_, kr_, s_, w_, R_, J_] :=
aj*R + cr*J + mr*R - tr*J - kr*R - s*R*J - w*J*R;

splot = StreamPlot[{f1[1, 1, 0, 0, 1, 1, 1, R, J],
g1[1, 1, 0, 0, 1, 1, 1, R, J]}, {J, -4, 4}, {R, -4, 4}]
Manipulate[
Show[splot,
ParametricPlot[
Evaluate[
First[{R[t], J[t]} /.
NDSolve[{J'[t] == f1[1, 1, 0, 0, 1, 1, 1, R[t], J[t]],
R'[t] == g1[1, 1, 0, 0, 1, 1, 1, R[t], J[t]],
Thread[{R[0], J[0]} == point]}, {R, J}, {t, 0, T}]]], {t, 0,
T}, PlotStyle -> Red]], {{T, 10}, 1, 100}, {{point, {1, 0}},
Locator}, SaveDefinitions -> True]