# Findroot to evaluated a function that become multivalued and varying of a parameter

I am having problem in solving this equation:

s[t_?NumericQ, l_?NumericQ] :=FindRoot[s - Sin[t - (l*s)] == 0, {s, t, l}, Method -> "Automatic"][[1, 2]]


When I try to plot it with this:

Manipulate[Plot[{s[t*(Pi), l], Sin[t*(Pi)]}, {t, 0, 4}], {l, 0, 10}]


it works for l < 1 but then the function have infintie derivative at than point and become multivalued.

My problem is not only to plot it but also use it in a differential equation (this represent the current phase relationship in a particular superconducting weak link).

Please, could you help in define this function correctly and possibly avoid the multiple solutions by imposing that at the points where the derivative is infintie the function should "jump" to the next smaller value (at increasing of variable t) and to the larger value (at decreasing for variable t).

Thanks a lot at who will help me.

• Consider "{s, t, l}"from your code. This means "start search from t". As is obvious from your code, the root is always between -1 and 1, it does not make sense to start the search with t>1. Try e.g. "s,0". Nov 9 '21 at 15:31
• Hi Daniel Huber, thanks for your suggestion. Of course it was a mistake from my side. I use now {s,0} but the probelm is still there. I should replace findroot with something that find all the existing roots. Any suggestion?
– Alex
Nov 9 '21 at 16:45

This can be done as a PDE. I show below the combination of derivative and initial conditions that gave a usable result.

deriv = D[s[l, t] - Sin[t - l*s[l, t]], l];
inits = {s[l, 0], s[0, t] - Sin[t]};
max = 10;
soln = NDSolveValue[Flatten[{deriv == 0, Thread[inits == 0]}],
s[l, t], {t, 0, max}, {l, 0, max}];


Plot the result:

Plot3D[soln, {t, 0, max}, {l, 0, max}, PlotPoints -> 50]


• Hi Daniel, thanks for you answer but I was not able to get your result. If I try to run your code I get tons of error meassages. Please, could you post the whole code you used (including definition of my function?) thank you.
– Alex
Nov 9 '21 at 16:16
• Hmm...I just copy/pasted the lines above and it worked fine. Even after clearing all symbols used in Global context. So I'm not sure what is going wrong for you. Do any of the symbols already have values in your session? Nov 9 '21 at 20:13
• OK. Now it works but the solution it does not look like what I expect at all. This should be a distorted sinusoid that for bigger l become multivalues.
– Alex
Nov 10 '21 at 10:57
• If you set max=20 you might see something more like what you expect. As for the multi-valued part, I think that by using a differential equation you get the desired continuity that imposes single-valuedness. Nov 10 '21 at 14:41
• The function has to be multivalued I will then discard manually the intermediated points between max and min. This will be an hysteretic function that wil jump discontinously from higher values to lower approaching from left at t1 and from lower values to higher valuse at t2 from righ with t1>t2. I hope this make sense. I want to plot everything and then will try to discard solution that has no physical sense.
– Alex
Nov 10 '21 at 15:18