How to numerically(or otherwise) solve these in mathematica(or matlab)

  • MATLAB
  • Thread starter caffeinemachine
  • Start date
  • Tags
    Matlab
In summary, to solve equations numerically in Mathematica or Matlab, one must first define the equation and its variables, then use a numerical solver function such as Solve, NSolve, or FindRoot. These functions will find solutions for the equation using numerical methods, such as iteration or interpolation. The output will give the numerical values for the variables that satisfy the equation. It is important to check the accuracy and convergence of the solution, as well as considering the limitations of numerical methods. Other options for solving equations in Mathematica or Matlab include using built-in functions or creating custom algorithms.
  • #1
caffeinemachine
Gold Member
MHB
816
15
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
 
Physics news on Phys.org
  • #2
caffeinemachine said:
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:
  • #3
CaptainBlack said:
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.
 
  • #4
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:
  • #5
BillSimpson said:
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.
Thank You BillSimpson for your reply.
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.
 
  • #6
caffeinemachine said:
...
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
 

FAQ: How to numerically(or otherwise) solve these in mathematica(or matlab)

How do I solve a system of linear equations in Mathematica or Matlab?

To solve a system of linear equations in Mathematica, you can use the Solve function. For example, if you have the equations 3x + 2y = 7 and 5x - 4y = 2, you can enter Solve[{3x + 2y == 7, 5x - 4y == 2}, {x, y}] in Mathematica to get the solutions. In Matlab, you can use the solve function in a similar way.

Can I solve differential equations in Mathematica or Matlab?

Yes, both Mathematica and Matlab have built-in functions for solving differential equations. In Mathematica, you can use the DSolve function, while in Matlab, you can use the ode45 function. You will need to provide the differential equation, initial conditions, and any other parameters required by the function.

How can I solve optimization problems in Mathematica or Matlab?

To solve optimization problems in Mathematica, you can use the Minimize or Maximize functions, depending on whether you want to minimize or maximize a function. In Matlab, you can use the fmincon function. You will need to provide the objective function, constraints, and any other parameters required by the function.

Is it possible to solve non-linear equations in Mathematica or Matlab?

Yes, both Mathematica and Matlab have functions for solving non-linear equations. In Mathematica, you can use the NSolve function, while in Matlab, you can use the fsolve function. You will need to provide the equations and initial guesses for the variables.

How do I solve a system of differential equations in Mathematica or Matlab?

To solve a system of differential equations in Mathematica, you can use the DSolve function, similar to solving a single differential equation. In Matlab, you can use the ode45 function with a system of equations. You will need to provide the differential equations, initial conditions, and any other parameters required by the function.

Similar threads

Replies
5
Views
2K
Replies
4
Views
1K
Replies
2
Views
4K
Replies
1
Views
1K
Replies
9
Views
2K
Replies
1
Views
1K
Replies
2
Views
4K
Replies
1
Views
3K
Back
Top