Mathematica: FindRoot for common tangent

杀马特。学长 韩版系。学妹 提交于 2019-12-14 02:12:40

问题


I asked this question a little while back that did help in reaching a solution. I've arrived at a somewhat acceptable approach but still not fully where I want it. Suppose there are two functions f1[x] and g1[y] that I want to determine the value of x and y for the common tangent(s). I can at least determine x and y for one of the tangents for example with the following:

f1[x_]:=(5513.12-39931.8x+23307.5x^2+(-32426.6+75662.x-43235.4x^2)Log[(1.-1.33333x)/(1.-1.x)]+x(-10808.9+10808.9x)Log[x/(1.-1.x)])/(-1.+x)
g1[y_]:=(3632.71+3806.87y-51143.6y^2+y(-10808.9+10808.9y)Log[y/(1.-1.y)]+(-10808.9+32426.6y-21617.7y^2)Log[1.-(1.y)/(1.-1.y)])/(-1.+y)

Show[
Plot[f1[x],{x,0,.75},PlotRange->All],
Plot[g1[y],{y,0,.75},PlotRange->All]
]

Chop[FindRoot[
{
(f1[x]-g1[y])/(x-y)==D[f1[x],x]==D[g1[y],y]
},
{x,0.0000001},{y,.00000001}
]
[[All,2]]
]

However, you'll notice from the plot that there exists another common tangent at slightly larger values of x and y (say x ~ 4 and y ~ 5). Now, interestingly if I slightly change the above expressions for f1[x] and g1[y] to something like the following:

    f2[x_]:=(7968.08-59377.8x+40298.7x^2+(-39909.6+93122.4x-53212.8x^2)Log[(1.-1.33333x)/(1.-1.x)]+x(-13303.2+13303.2x)Log[x/(1.-1.x)])/(-1.+x)
    g2[y_]:=(5805.16-27866.2y-21643.y^2+y(-13303.2+13303.2y)Log[y/(1.-1.y)]+(-13303.2+39909.6y-26606.4y^2)Log[1.-(1.y)/(1.-1.y)])/(-1.+y)

    Show[
    Plot[f2[x],{x,0,.75},PlotRange->All],
    Plot[g2[y],{y,0,.75},PlotRange->All]
    ]

    Chop[FindRoot[
    {
    (f2[x]-g2[y])/(x-y)==D[f2[x],x]==D[g2[y],y]
    },
    {x,0.0000001},{y,.00000001}
    ]
    [[All,2]]
    ]

And use the same method to determine the common tangent, Mathematica chooses to find the larger values of x and y for the positive sloping tangent.

Finally, my question: is it possible to have Mathematica find both the high and low x and y values for the common tangent and store these values in a similar way that allows me to make a list plot? The functions f and g above are all complex functions of another variable, z, and I am currently using something like the following to plot the tangent points (should be two x and two y) as a function of z.

ex[z_]:=Chop[FindRoot[
{
(f[x,z]-g[y,z])/(x-y)==D[f[x],x]==D[g[y],y]
},
{x,0.0000001},{y,.00000001}
]
[[All,2]]
]

ListLinePlot[
Table[{ex[z][[i]],z},{i,1,2},{z,1300,1800,10}]
]

回答1:


To find estimates for {x, y} that would solve your equations, you could plot them in ContourPlot and look for intersection points. For example

f1[x_]:=(5513.12-39931.8 x+23307.5 x^2+(-32426.6+75662. x- 
    43235.4 x^2)Log[(1.-1.33333 x)/(1.-1.x)]+
    x(-10808.9+10808.9 x) Log[x/(1.-1.x)])/(-1.+x)
g1[y_]:=(3632.71+3806.87 y-51143.6 y^2+y (-10808.9+10808.9y) Log[y/(1.-1.y)]+
    (-10808.9+32426.6 y-21617.7 y^2) Log[1.-(1.y)/(1.-1.y)])/(-1.+y)

plot = ContourPlot[{f1'[x] == g1'[y], f1[x] + f1'[x] (y - x) == g1[y]}, 
   {x, 0, 1}, {y, 0, 1}, PlotPoints -> 40]

As you can see there are 2 intersection points in the interval (0,1). You could then read off the points from the graph and use these as starting values for FindRoot:

seeds = {{.6,.4}, {.05, .1}};
sol = FindRoot[{f1'[x] == g1'[y], f1[x] + f1'[x] (y - x) == g1[y]}, 
    {x, #1}, {y, #2}] & @@@ seeds

To get the pairs of points from sol you can use ReplaceAll:

points = {{x, f1[x]}, {y, g1[y]}} /. sol

(* 
 ==> {{{0.572412, 19969.9}, {0.432651, 4206.74}}, 
      {{0.00840489, -5747.15}, {0.105801, -7386.68}}}
*)

To show that these are the correct points:

Show[Plot[{f1[x], g1[x]}, {x, 0, 1}],
 {ParametricPlot[#1 t + (1 - t) #2, {t, -5, 5}, PlotStyle -> {Gray, Dashed}],
  Graphics[{PointSize[Medium], Point[{##}]}]} & @@@ points]




回答2:


OK, so let's quickly rewrite what you've done so far:

Using your f1 and g1, we have the plot

plot = Plot[{f1[x], g1[x]}, {x, 0, .75}]

and the first shared tangent at

sol1 = Chop[FindRoot[{(f1[x] - g1[y])/(x - y) == D[f1[x], x] == D[g1[y], y]}, 
    {x, 0.0000001}, {y, .00000001}]]

(* {x -> 0.00840489, y -> 0.105801} *)

Define the function

l1[t_] = (1 - t) {x, f1[x]} + t {y, g1[y]} /. sol1

then, you can plot the tangents using

Show[plot, Graphics[Point[{l1[0], l1[1]}]], 
     ParametricPlot[l1[t], {t, -1, 2}], 
     PlotRange -> {{-.2, .4}, {-10000, 10000}}]


I briefly note (for my own sake) that the equations you used (e.g., to generate sol1 above) come from requiring that the tangent line for f1 at x tangentially hits g1 at some point y, i.e.,

LogicalExpand[{x, f[x]} + t {1, f'[x]} == {y, g[y]} && f'[x] == g'[y]]

To investigate where the shared tangents lie, you can use a Manipulate:

Manipulate[Show[plot, ParametricPlot[{x, f1[x]} + t {1, f1'[x]}, {t, -1, 1}]], 
       {x, 0, .75, Appearance -> "Labeled"}]

which produces something like

Using the eyeballed values for x and y, you can get the actual solutions using

sol = Chop[Table[
   FindRoot[{(f1[x] - g1[y])/(x - y) == D[f1[x], x] == D[g1[y], y]},
    {x, xy[[1]]}, {y, xy[[2]]}], {xy, {{0.001, 0.01}, {0.577, 0.4}}}]]

define the two tangent lines using

l[t_] = (1 - t) {x, f1[x]} + t {y, g1[y]} /. sol

then

Show[plot, Graphics[Point[Flatten[{l[0], l[1]}, 1]]], 
 ParametricPlot[l[t], {t, -1, 2}, PlotStyle -> Dotted]]


This process could be automated, but I'm not sure how to do it efficiently.



来源:https://stackoverflow.com/questions/8993850/mathematica-findroot-for-common-tangent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!