# how to numerically(or otherwise) solve these in mathematica(or matlab)

#### caffeinemachine

##### Well-known member
MHB Math Scholar
The values of t_1,t_2 and t_3 are to be found out corresponding to the values of the other variables inputted by the user.
I tried using "FindRoot" in Mathematica 7 but it says "solutions don't converge, perturb the initial values". I tried many set of initial values but none worked.

Is there a way to solve this??

cos(t_3)*l_3*cos(t_1)*cos(t_2)-cos(t_3)*l_3*sin(t_1)*cos(a_1)*sin(t_2)+sin(t_1)*sin(a_1)*sin(t_3)*l_3+cos(t_1)*l_1+l_7+cos(t_7)*l_6=0

cos(t_3)*l_3*cos(t_1)*cos(a_1)*sin(t_2)+cos(t_3)*l_3*sin(t_1)*cos(t_2)+sin(t_1)*l_1-cos(t_1)*sin(a_1)*sin(t_3)*l_3-sin(t_7)*cos(a_7)*l_6+s_7*sin(a_7)=0

sin(a_1)*sin(t_2)*cos(t_3)*l_3+cos(a_1)*sin(t_3)*l_3+sin(t_7)*sin(a_7)*l_6+s_7*cos(a_7)+s_1=0

#### CaptainBlack

##### Well-known member
The values of t_1,t_2 and t_3 are to be found out corresponding to the values of the other variables inputted by the user.
I tried using "FindRoot" in Mathematica 7 but it says "solutions don't converge, perturb the initial values". I tried many set of initial values but none worked.

Is there a way to solve this??

cos(t_3)*l_3*cos(t_1)*cos(t_2)-cos(t_3)*l_3*sin(t_1)*cos(a_1)*sin(t_2)+sin(t_1)*sin(a_1)*sin(t_3)*l_3+cos(t_1)*l_1+l_7+cos(t_7)*l_6=0

cos(t_3)*l_3*cos(t_1)*cos(a_1)*sin(t_2)+cos(t_3)*l_3*sin(t_1)*cos(t_2)+sin(t_1)*l_1-cos(t_1)*sin(a_1)*sin(t_3)*l_3-sin(t_7)*cos(a_7)*l_6+s_7*sin(a_7)=0

sin(a_1)*sin(t_2)*cos(t_3)*l_3+cos(a_1)*sin(t_3)*l_3+sin(t_7)*sin(a_7)*l_6+s_7*cos(a_7)+s_1=0
Does FindRoot attempt to find a numerical of symbolic solution? .. OK Google can answer this one as: numerical. Have you forced FindRoot to not use symbolic computations as suggested in the documentation?

Are you sure that there is a solution for the values of parameters you are interested in?

It may be worth adding the constraints $$-\pi \le t_1,t_2,t_3 < \pi$$.

My personal approach to this kind of problem is brute force, form an objective function equal to the sum of the squares of the left hand sides then employ a global optimisation method to find the minimum of the objective in the feasible cube. If the minimum is sufficiently small to suggest the presense of a zero near by use the minimising point as a start point in some more sophisticated solution method.

CB

Last edited:

#### caffeinemachine

##### Well-known member
MHB Math Scholar
Does FindRoot attempt to find a numerical of symbolic solution? .. OK Google can answer this one as: numerical. Have you forced FindRoot to not use symbolic computations as suggested in the documentation?

Are you sure that there is a solution for the values of parameters you are interested in?

It may be worth adding the constraints $$-\pi \le t_1,t_2,t_3 < \pi$$.

My personal approach to this kind of problem is brute force, form an objective function equal to the sum of the squares of the left hand sides then employ a global optimisation method to find the minimum of the objective in the feasible cube. If the minimum is sufficiently small to suggest the presense of a zero near by use the minimising point as a start point in some more sophisticated solution method.

CB
Thank you CaptainBlack for your reply. These equations result from the analysis of spatial 7R linkage. I can't be sure that there is a solution for the values of the parameters I am entering. If you know about spatial mechanism then you would also have sympathy with me
As for the inequality you mentioned in your post, frustratingly, mathematica doesn't entertain inequalities in its methods like FindRoot, NSolve etc which are numerical solvers. Inequalities are allowed in "exact solvers".

"Have you forced FindRoot to not use symbolic computations as suggested in the documentation?". I don't know what is meant by this. Can you give me the link of the documentation you are talking about.

Sadly, I am not trained in any theory numerical techniques at all, not at this point at least. So I can't understand the approach you mention in the last paragraph of your post.

#### BillSimpson

##### New member
We have no information on the domain of your input variables, but for some values the minimum with respect to t1,t2,t3 of the sum of squared error of your three equations is much greater than zero.

Here is an example that searches for a set of parameters and then finds t1,t2,t3 that has a minimum squared error near zero.

In[17]:= While[True,
a1=RandomReal[{-Pi,Pi}];a7=RandomReal[{-Pi,Pi}]; l1=RandomReal[{-Pi,Pi}];
l3=RandomReal[{-Pi,Pi}];l6=RandomReal[{-Pi,Pi}];l7=RandomReal[{-Pi,Pi}];
s1=RandomReal[{-Pi,Pi}];s7=RandomReal[{-Pi,Pi}];t7=RandomReal[{-Pi,Pi}];
v=NMinimize[
(Cos[t3]*l3*Cos[t1]*Cos[t2]-Cos[t3]*l3*Sin[t1]*Cos[a1]*Sin[t2]+Sin[t1]*Sin[a1]*Sin[t3]*l3+Cos[t1]*l1+l7+ Cos[t7]*l6)^2+
(Cos[t3]*l3*Cos[t1]*Cos[a1]*Sin[t2]+Cos[t3]*l3*Sin[t1]*Cos[t2]+Sin[t1]*l1-Cos[t1]*Sin[a1]*Sin[t3]*l3-Sin[t7]*Cos[a7]*l6+ s7*Sin[a7])^2+
(Sin[a1]*Sin[t2]*Cos[t3]*l3+Cos[a1]*Sin[t3]*l3+Sin[t7]*Sin[a7]*l6+s7*Cos[a7]+s1)^2,
{t1,t2,t3}];
If[First[v]<.001,Break[]]
];
{a1,a7,l1,l3,l6,l7,s1,s7,t7,v}

Out[18]={0.9676285734957135, -0.6055832455969292, 0.7416052518248044,
-2.4754030471760835, -0.139880741669415, -1.387680009683257,
-2.5026792960158537, 0.3545824940403457, -2.7526143572135373,
{6.001980115750534*^-32,{t1-> -0.7680206685789617,t2-> -1.5678943805744407, t3-> -0.1648144297428493}}}

You can modify that to fix the values of some of your parameters if they are known or to generate random values within a given range or possibly even to include a some of those parameters in the NMinimize search.

Last edited:

#### caffeinemachine

##### Well-known member
MHB Math Scholar
We have no information on the domain of your input variables, but for some values the minimum with respect to t1,t2,t3 of the sum of squared error of your three equations is much greater than zero.

Here is an example that searches for a set of parameters and then finds t1,t2,t3 that has a minimum squared error near zero.

In[17]:= While[True,
a1=RandomReal[{-Pi,Pi}];a7=RandomReal[{-Pi,Pi}]; l1=RandomReal[{-Pi,Pi}];
l3=RandomReal[{-Pi,Pi}];l6=RandomReal[{-Pi,Pi}];l7=RandomReal[{-Pi,Pi}];
s1=RandomReal[{-Pi,Pi}];s7=RandomReal[{-Pi,Pi}];t7=RandomReal[{-Pi,Pi}];
v=NMinimize[
(Cos[t3]*l3*Cos[t1]*Cos[t2]-Cos[t3]*l3*Sin[t1]*Cos[a1]*Sin[t2]+Sin[t1]*Sin[a1]*Sin[t3]*l3+Cos[t1]*l1+l7+ Cos[t7]*l6)^2+
(Cos[t3]*l3*Cos[t1]*Cos[a1]*Sin[t2]+Cos[t3]*l3*Sin[t1]*Cos[t2]+Sin[t1]*l1-Cos[t1]*Sin[a1]*Sin[t3]*l3-Sin[t7]*Cos[a7]*l6+ s7*Sin[a7])^2+
(Sin[a1]*Sin[t2]*Cos[t3]*l3+Cos[a1]*Sin[t3]*l3+Sin[t7]*Sin[a7]*l6+s7*Cos[a7]+s1)^2,
{t1,t2,t3}];
If[First[v]<.001,Break[]]
];
{a1,a7,l1,l3,l6,l7,s1,s7,t7,v}

Out[18]={0.9676285734957135, -0.6055832455969292, 0.7416052518248044,
-2.4754030471760835, -0.139880741669415, -1.387680009683257,
-2.5026792960158537, 0.3545824940403457, -2.7526143572135373,
{6.001980115750534*^-32,{t1-> -0.7680206685789617,t2-> -1.5678943805744407, t3-> -0.1648144297428493}}}

You can modify that to fix the values of some of your parameters if they are known or to generate random values within a given range or possibly even to include a some of those parameters in the NMinimize search.
I don't entirely understand what you are trying to say here since I am a dud at this. But I am sure this will help me as I spend more time into this aspect of mechanism simulation with some help from my guide.

#### CaptainBlack

##### Well-known member
...
Sadly, I am not trained in any theory numerical techniques at all, not at this point at least. So I can't understand the approach you mention in the last paragraph of your post.
The brute force method I often start with is simple random (stochastic) search over the feasible region, since this is the only global optimisation method which provably converges (in probability IIRC) to a minimum for arbitrary objective functions. The formation of the objective is illustrated in BillSimpson's post.

Also in Nminimize it might be worth specifying a non default method, DifferentialEvolution might give interesting results.

CB