I created the function getSolution[xVal,yVal] for a geometry problem I'm working on and wish to solve it for getSolution[2,x]==0. I can plot it clearly showing the roots:
However, when I attempt to solve
FindRoot[getSolution[2, x] == 0, {x, 1.5}]
I receive the errors:
Part::partd: Part specification x$18835[[2]] is longer than depth of object.
Part::partd: Part specification x$18835[[1]] is longer than depth of object.
Which I've tracked down I believe to FindRoot attempting to obtain the derivative of the function for the Newton method. Since if I code:
D[getSolution[2, x], x]
I receive the same message. I was wondering if someone could offer some suggestions to fix this code? Here's my code:
getAngle[a_, b_, c_] := Module[{line1, line2, line3, aVal, bVal, val},
aVal = a - b;
bVal = c - b;
val = (aVal.bVal)/(EuclideanDistance[{0, 0},
aVal] EuclideanDistance[{0, 0}, bVal]);
ArcCos[val]
];
makeEqn[p1_, p2_] :=
Function[{x}, (p2[[2]] - p1[[2]])/(p2[[1]] - p1[[1]]) (x -
p1[[1]]) + p1[[2]]];
getLength[a_, b_] := EuclideanDistance[a, b];
getSolution[cx_, cy_] :=
Module[{c, m, acLength, macAngle, d, ebLength, bmLength, emLength,
acEqn, acAngle, e, deEqn, cbEqn, f, x, a, b},
a = {0, 0};
b = {7, 0};
c = {cx, cy};
m = {getLength[a, b]/2, 0};
acLength = getLength[a, c];
macAngle = getAngle[m, a, c];
d = {acLength Cos[macAngle], 0};
bmLength = getLength[b, m];
acEqn = makeEqn[a, c];
e = {x, acEqn[x]} /.
NSolve[acEqn[x]^2 + (x - m[[1]])^2 == bmLength^2 && x > 0, x] //
First;
deEqn = makeEqn[d, e];
cbEqn = makeEqn[c, b];
f = {x, deEqn[x]} /. NSolve[deEqn[x] == cbEqn[x], x] // First;
getLength[e, b] - getLength[f, b] // N
]
Not sure this is needed but here's the problem: Essentially need to find the point C in the diagram such that the triangle FEB is isosceles. When getSolution[x,y]=0, it is. Also, don't wish to just generate a table of values and find it manually for one case as above as I wish to solve the larger problem getSolution[x,y]=0 for all x and y in applicable domain.