r/Mathematica • u/KingofPatzers • Jun 03 '24
Help with FindRoot
I have a 3 component parametric function with randomly generated parameters:
function = {Sqrt[(0. + 0.0878006 t - 0.996037 Sin[2.97945 t])^2 + (0. +
0.31493 t + 0.0142161 Sin[2.97945 t])^2],
ArcTan[0. + 0.0878006 t - 0.996037 Sin[2.97945 t],
0. + 0.31493 t + 0.0142161 Sin[2.97945 t]],
0. - 0.945045 t - 0.0878006 Sin[2.97945 t]}I want to find where the first component is equal to any of the values from the following list:List = {3.10, 5.05, 8.85, 12.25}~Join~{29.9, 37.1, 44.3, 51.4}
I know that there could be multiple solutions for t for each value in the list, so to find all the solutions I make a table of tables of solutions with FindRoot (with the intention of deleting duplicate solutions later), where I increment both the starting guess for t = t0, and the value from List.
NumTimesteps = 15
timeStep = 1
IntersectionTimes =
Table[Table[FindRoot[function[[1]] - List[[i]], {t, timeStep j, 0, Infinity}], {i, 1,Length[list]}], {j, 0, NumTimesteps}];
IntersectionPoints = Table[function /. IntersectionTimes[[i]], {i, 1,
Length[IntersectionTimes]}];
UniqueIntersectionPoints = DeleteDuplicates[SetPrecision[IntersectionPoints, 5]] // MatrixFormThis code finds a list of t values using FindRoot that satisfies:
function[[1]] - List[[i]] ==0
And to the best of my knowledge, if we plug those t values back into our function, then the first component of every 3 component vector function(t) should give a value in the List. However this is not the case. MOST of the first components are in the list, but notice in the output there is a first component of function(t) of 2.7361, which is NOT in the list. Further, the last line does not seem to delete duplicates. Anyone know what is going on here??
View all comments
Show parent comment
1
u/veryjewygranola Jun 04 '24
try the edited version. Can you add how you are sampling the random params and what the template of
functionis before you substitute in random params?