0

I want to combine InterpolationFunction objects, results of an NDSolve in a loop, into one function. This is my code:

k1 = 3; sin = 2; \[Alpha] = 0.5;

[Mu][s_, t_] := (0.35)s[t]/(0.7 + s[t] + ((s[t])^2)(0.6) );

um = 0.097032; up = 0.2093;

k2 = 5.6; [Beta] = 0.33; [Tau] = 3;

s0 = 0.1; x0 = 0.2;

steps = 65;

PiecesX = {}; PiecesS = {}; Conditions = {}; Starts = {{s0, x0}};

For[i = 1, i <= Ceiling[steps/[Tau]], i++, s0 = Starts[[i]][[1]]; x0 = Starts[[i]][[2]]; u = um; te = (i - 1)[Tau]; [Omega] = Floor[te/[Tau]][Tau]; k = [Beta]k2[Mu][ssol, [Omega]]xsol[[Omega]]; If[k > um && k < up, u = k]; If[k >= up, u = up]; {ssol, xsol} = NDSolveValue[{s'[t] == -k1[Mu][s, t]x[t] + u(sin - s[t]), x'[t] == ([Mu][s, t] - [Alpha]u)x[t], s[(i - 1)*[Tau]] == s0, x[(i - 1)*[Tau]] == x0}, {s, x}, {t, (i - 1)[Tau], i[Tau]}]; AppendTo[PiecesS, ssol]; AppendTo[PiecesX, xsol]; AppendTo[Conditions, (i - 1)*[Tau] < t < i[Tau]]; AppendTo[Starts, {ssol[i[Tau]], xsol[i*[Tau]]}]; ];

solX = Piecewise[Transpose[{PiecesX, Conditions}]]; solS = Piecewise[Transpose[{PiecesS, Conditions}]];

The functions solX and solS look like normal piecewise functions in output, but refuse to be plotted. Can someone tell me what i am doing wrong?

  • Could you fix the incorrect syntax? 1) This is incorrect [Mu] - it should be \[Mu], same for Alpha and Tau if you meant the symbols. 2) sin is wrong. It should be Sin. Also there are loads of things you haven't given us here like the values of mu, alpha, s0, x0, u ... etc How do you expect anybody to run your code without them? – flinty Nov 04 '21 at 17:38
  • Sorry, yes, I am new to this, so I tought I had an obvious mistake, didnt want to make it heavy with constants sorry – Borislava Dimitrova Nov 04 '21 at 17:45
  • That now seems to work fine for me: Plot[solX[t], {t, 0, 66}] produces a curve. – flinty Nov 04 '21 at 17:55
  • Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – LouisB Nov 04 '21 at 22:26
  • Related/duplicate: https://mathematica.stackexchange.com/questions/19042/how-to-splice-together-several-instances-of-interpolatingfunction – Michael E2 Nov 05 '21 at 01:32

0 Answers0