# equation solving – FindRoot inside Table/MapThread

I have a function `Sdiff(zm, zl, (Sigma), zh)` such that I have a list of 11 values for each variables `zl`, `(Sigma)`, and `zh` listed below as `zq1`, `(Sigma)1`, and `zh1`. I want to find the root of `Sdiff(zm, zl, (Sigma), zh)`, i.e. find `zm` where `Sdiff(zm, zl, (Sigma), zh)==0` for each given values of `zl`, `(Sigma)`, and `zh`.

Just a note, I should get 11 roots since there are 11 values for each `zl`, `(Sigma)`, and `zh`. There is an example below in my code which tried to find the root of `Sdiff(zm, 0.937858, -1.47, 1)`. Notice that I picked the first entries of `zl`, `(Sigma)`, and `zh`.

The problem here is that when I try to find the root, I need to specify a value that is close to the root. For `Sdiff(zm, 0.937858, -1.47, 1)` I input `{zm, 1.313}`, but the roots will be larger as I increase `zl`, `(Sigma)`, and `zh`. So how can I make a `Table` or `MapThread` to accommodate all the roots? For `Sdiff(zm, 93.0506, -155, 100)` I input `{zm, 131.2}` which is very big compared to the previous.

``````d = 3;
ag = 10;
pg = 10;
wp = 20;
f(z_, zh_) := 1 - (z/zh)^(d + 1);
func1(z_?NumericQ, zm_?NumericQ, zl_?NumericQ, (Sigma)_?NumericQ, zh_?NumericQ) := Module({zr, zmr, zlr, (Sigma)r, zhr}, {zr, zmr, zlr, (Sigma)r, zhr} = Rationalize({z, zm, zl, (Sigma), zh}, 0); zmr^d/(zr^d Sqrt(f(zr, zhr) zmr^(2 d) - f(zmr, zhr) zr^(2 d))) - zlr^d/(zr^d Sqrt(f(zr, zhr) (zlr^(2 d) - (f(zlr, zhr) zr^(2 d))/(f(zlr, zhr) + (Sigma)r^2)))))
func2(z_?NumericQ, zm_?NumericQ, zl_?NumericQ, zh_?NumericQ) := Module({zr, zmr, zlr, zhr}, {zr, zmr, zlr, zhr} = Rationalize({z, zm, zl, zh}, 0); zmr^d/(zr^d Sqrt(f(zr, zhr) zmr^(2 d) - f(zmr, zhr) zr^(2 d))))
Sdiff1(zm_?NumericQ, zl_?NumericQ, (Sigma)_?NumericQ, zh_?NumericQ) := Module({zlr = Rationalize(zl, 0)}, NIntegrate(func1(z, zm, zlr, (Sigma), zh), {z, 0, zlr}, AccuracyGoal -> ag, PrecisionGoal -> pg, WorkingPrecision -> wp) - 1/zlr^(d - 1))
Sdiff2(zm_?NumericQ, zl_?NumericQ, zh_?NumericQ) := Module({zlr, zmr}, {zlr, zmr} = Rationalize({zl, zm}, 0); NIntegrate(func2(z, zmr, zlr, zh), {z, zlr, zmr}, AccuracyGoal -> ag, PrecisionGoal -> pg, WorkingPrecision -> wp))
Sdiff(zm_?NumericQ, zl_?NumericQ, (Sigma)_?NumericQ, zh_?NumericQ) := Sdiff1(zm, zl, (Sigma), zh) + Sdiff2(zm, zl, zh)

In(50):= FindRoot(Sdiff(zm, 0.937858, -1.47, 1) == 0, {zm, 1.313}) // AbsoluteTiming

Out(50)= {12.78, {zm -> 1.31315}}

In(51):= FindRoot(Sdiff(zm, 9.30684, -15.5, 10) == 0, {zm, 13.12}) // AbsoluteTiming

Out(51)= {10.3786, {zm -> 13.128}}

In(52):= FindRoot(Sdiff(zm, 93.0506, -155, 100) == 0, {zm, 131.2}) // AbsoluteTiming

Out(52)= {8.39542, {zm -> 131.279}}

zq1 = {0.937858, 9.30684, 18.6124, 27.9182, 37.2237, 46.5288, 55.8341, 65.1388, 74.4432, 83.7471, 93.0506};
(Sigma)1 = {-1.471551293, -15.50176577, -31.01646875, -46.52851902, -62.04170567, -77.55674550, -93.07071265, -108.5876350, -124.1060283, -139.6268987, -155.1497506};
zh1 = {1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};

eq(zm_?NumericQ, zl_?NumericQ, (Sigma)_?NumericQ, zh_?NumericQ) := Sdiff(zm, zl, (Sigma), zh) == 0
In(21):= eqroot = MapThread(eq(zm, #1, #2, #3) &, {zq1, (Sigma)1, zh1})

Out(21)= {eq(zm, 0.937858, -1.47155, 1),
eq(zm, 9.30684, -15.5018, 10), eq(zm, 18.6124, -31.0165, 20),
eq(zm, 27.9182, -46.5285, 30), eq(zm, 37.2237, -62.0417, 40),
eq(zm, 46.5288, -77.5567, 50), eq(zm, 55.8341, -93.0707, 60),
eq(zm, 65.1388, -108.588, 70), eq(zm, 74.4432, -124.106, 80),
eq(zm, 83.7471, -139.627, 90), eq(zm, 93.0506, -155.15, 100)}
$$```$$
``````