MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# Thread Subject: Solving a (complicated) equation system

 Subject: Solving a (complicated) equation system From: Matt Date: 18 Jun, 2012 14:10:07 Message: 1 of 18 Hello ! I have a quite difficult system of equations to solve. I am desperate to find the solution now to this problem. Here are the equations I have at my disposal : tan(alphaAR)*(R*cos(beta))==ee beta==asin((xg-ee)/R) tan(delta-alphaAV)==((L-ee)/(R*cos(beta))) I know the values of : R, xg, alphaAV, L, alphaAR So basically there are 3 equations with 3 unkown variables. I want to find the value of beta, ee and delta. I tried to solve this but without success. Even when I first try to solve the first 3 equations together by doing : solve(tan(alphaAR)*(Rvirage*cos(beta))==ee,beta==asin((xg-ee)/Rvirage),tan(delta-alphaAV)==((L-ee)/(Rvirage*cos(beta)))) I get an error : ----------------------------------------------------------- Error using beta (line 21) Not enough input arguments. Error in simpletab>finalcheck_Callback (line 2368) solve(tan(alphaAR)*(Rvirage*cos(beta))==ee,beta==asin((xg-ee)/Rvirage),tan(delta-alphaAV)==((L-ee)/(Rvirage*cos(beta)))) Error in gui_mainfcn (line 96)         feval(varargin{:}); Error in simpletab (line 22)     gui_mainfcn(gui_State, varargin{:}); Error in @(hObject,eventdata)simpletab('finalcheck_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating uicontrol Callback ---------------------------------------------------------------------- Thanks a lot for any help I could get ! :-)
 Subject: Solving a (complicated) equation system From: Steven_Lord Date: 18 Jun, 2012 14:31:13 Message: 2 of 18 "Matt " wrote in message news:jrncrv\$cjl\$1@newscl01ah.mathworks.com... > Hello ! > > I have a quite difficult system of equations to solve. I am desperate to > find the solution now to this problem. Here are the equations I have at my > disposal : > > tan(alphaAR)*(R*cos(beta))==ee > beta==asin((xg-ee)/R) > tan(delta-alphaAV)==((L-ee)/(R*cos(beta))) > > I know the values of : > > R, xg, alphaAV, L, alphaAR > > So basically there are 3 equations with 3 unkown variables. > > I want to find the value of beta, ee and delta. > > I tried to solve this but without success. Even when I first try to solve > the first 3 equations together by doing : > > solve(tan(alphaAR)*(Rvirage*cos(beta))==ee,beta==asin((xg-ee)/Rvirage),tan(delta-alphaAV)==((L-ee)/(Rvirage*cos(beta)))) > > I get an error : > > ----------------------------------------------------------- > Error using beta (line 21) > Not enough input arguments. Define beta to be a symbolic variable. Since you're doing this inside a function file, I would use SYM instead of SYMS: beta = sym('beta'); % instead of syms beta The latter "poofs" the variable into the workspace at runtime, after MATLAB has parsed the file. When it parsed the file, MATLAB needed to know to what the identifier beta referred; since there is a BETA function and nothing that it could tell indicated that beta should be a variable, it was treated as a call to the function with 0 inputs. The former makes it clear that beta is a variable (since it appears on the left side of an equals sign.) -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
 Subject: Solving a (complicated) equation system From: Torsten Date: 18 Jun, 2012 14:40:47 Message: 3 of 18 Maybe syms Rvirage, xg, alphaAV, L, alphaAR, beta, ee, delta solve(tan(alphaAR)*(Rvirage*cos(beta))==ee,beta==asin((xg-ee)/ Rvirage),tan(
 Subject: Solving a (complicated) equation system From: Matt Date: 18 Jun, 2012 14:50:07 Message: 4 of 18 Thank you both for the VERY QUICK answers ! I've tried to re-organize a bit the function : beta = sym('beta'); equ4='tan(alphaAR)==ee/(R*cos(beta))' equ5='sin(beta)==((xg-ee)/R)' equ6='tan(delta-alphaAV)==((L-ee)/(R*cos(beta)))' [beta, delta, ee]=solve(equ4,equ5,equ6,'delta','beta','ee') Again the following variables are defined previously in the program : alphaAR, R, xg, alphaAV, L Now I'm getting the following error, despite the fact that the syntax of that seems allright to me ! ------------------------------------- Error using solve>processString (line 337) ' tan(alphaAR)==ee/(40*cos(beta)) ' is not a valid expression or equation. Error in solve>getEqns (line 267)       eqns = processString(eqns, v, vc); Error in solve (line 150) [eqns,vars,options] = getEqns(varargin{:}); Error in simpletab>finalcheck_Callback (line 2378) [beta, delta, ee]=solve(equ4,equ5,equ6,'delta','beta','ee') Error in gui_mainfcn (line 96)         feval(varargin{:}); Error in simpletab (line 22)     gui_mainfcn(gui_State, varargin{:}); Error in @(hObject,eventdata)simpletab('finalcheck_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating uicontrol Callback ------------------------------------ Thanks a lot again ! :-)
 Subject: Solving a (complicated) equation system From: Matt Date: 18 Jun, 2012 14:55:08 Message: 5 of 18 And if I try to add a "d" after all trigonometric functions (since I'm working on degrees), here is what I get (a little bit better) : Warning: Explicit solution could not be found. > In solve at 169   In simpletab>finalcheck_Callback at 2378   In gui_mainfcn at 96   In simpletab at 22   In @(hObject,eventdata)simpletab('finalcheck_Callback',hObject,eventdata,guidata(hObject))   beta =   [ empty sym ]   delta =      [] ee =      []
 Subject: Solving a (complicated) equation system From: Steven_Lord Date: 18 Jun, 2012 18:49:11 Message: 6 of 18 "Matt " wrote in message news:jrnf6v\$o4p\$1@newscl01ah.mathworks.com... > Thank you both for the VERY QUICK answers ! I've tried to re-organize a > bit the function : > > beta = sym('beta'); > > equ4='tan(alphaAR)==ee/(R*cos(beta))' Do not specify your expressions as strings. Also, this syntax will only work if you're using release R2012a or later, I believe. For earlier releases, you'd probably want to rearrange this to read: equ4 = tan(alphaAR) - ee/(R*cos(beta)); and similarly for the other equations. > equ5='sin(beta)==((xg-ee)/R)' > equ6='tan(delta-alphaAV)==((L-ee)/(R*cos(beta)))' > > [beta, delta, ee]=solve(equ4,equ5,equ6,'delta','beta','ee') > > Again the following variables are defined previously in the program : > > alphaAR, R, xg, alphaAV, L Because you specified your equations as strings, SOLVE cannot "see" those previously defined values. *snip* -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
 Subject: Solving a (complicated) equation system From: Christopher Creutzig Date: 19 Jun, 2012 14:10:03 Message: 7 of 18 On 18.06.12 16:55, Matt wrote: > And if I try to add a "d" after all trigonometric functions (since I'm working on degrees), here is what I get (a little bit better) : sind etc. are currently not supported for symbolic input. I wrote a little bit about the reasons just recently here; additionally, the error you received indicates that you tried putting them in a string. Christopher
 Subject: Solving a (complicated) equation system From: Matt Date: 20 Jun, 2012 06:37:09 Message: 8 of 18 Thanks everybody for the help ! I' modified the equation : beta = sym('beta'); solve(tand(alphaAR)==(xg-R*sind(beta))/(R*cosd(beta)),beta) assignin('base', 'beta', beta) If I try to solve it using another math program, I get 2 solutions for this equation, but with Matlab, all I get is : ----------------------------------------- Undefined function 'sind' for input arguments of type 'sym'. Error in simpletab>finalcheck_Callback (line 2381) solve(tand(alphaAR)==(xg-R*sind(betaa))/(R*cosd(betaa)),betaa) Error in gui_mainfcn (line 96)         feval(varargin{:}); Error in simpletab (line 22)     gui_mainfcn(gui_State, varargin{:}); Error in @(hObject,eventdata)simpletab('finalcheck_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating uicontrol Callback ---------------------------------------- I've read the help section and tried different methods for this, without success !
 Subject: Solving a (complicated) equation system From: Steven_Lord Date: 20 Jun, 2012 13:39:31 Message: 9 of 18 "Matt " wrote in message news:jrrr2l\$71n\$1@newscl01ah.mathworks.com... > Thanks everybody for the help ! I' modified the equation : > > beta = sym('beta'); > solve(tand(alphaAR)==(xg-R*sind(beta))/(R*cosd(beta)),beta) Call SOLVE with an output argument. > assignin('base', 'beta', beta) > > If I try to solve it using another math program, I get 2 solutions for > this equation, but with Matlab, all I get is : > > ----------------------------------------- > Undefined function 'sind' for input arguments of type 'sym'. The degree-based trig functions are not defined for symbolic objects. Solve using SIN, COS, TAN (which ARE defined for symbolic objects) and then convert the result from radians to degrees. *snip* -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
 Subject: Solving a (complicated) equation system From: Matt Date: 28 Jun, 2012 13:59:08 Message: 10 of 18 I've converted my equation to radians : solve(tan(0.02913639281699945036921220856349)==(1-40*sin(beta))/(40*cos(beta)),beta) But I get the following error : ---------------------------------------------- Error using beta (line 21) Not enough input arguments. Error in testequ (line 2) solve(tan(0.02913639281699945036921220856349)==(1-40*sin(beta))/(40*cos(beta)),beta) ------------------------------------------------ I know the trigonometric equations are kind of annoying to solve since there can be many solutions but there I cannot even get to the point I can calculate this. With Mathematica I can solve but I want to solve this with Matlab. Thanks a lot for the help ! :)
 Subject: Solving a (complicated) equation system From: Nasser M. Abbasi Date: 28 Jun, 2012 14:27:21 Message: 11 of 18 On 6/28/2012 8:59 AM, Matt wrote: > I've converted my equation to radians : > > solve(tan(0.02913639281699945036921220856349)==(1-40*sin(beta))/(40*cos(beta)),beta) > > But I get the following error : > > ---------------------------------------------- > Error using beta (line 21) > Not enough input arguments. > > Error in testequ (line 2) > solve(tan(0.02913639281699945036921220856349)==(1-40*sin(beta))/(40*cos(beta)),beta) > ------------------------------------------------ > > I know the trigonometric equations are kind of annoying to solve since there can > be many solutions but there I cannot even get to the point I can calculate this. >With Mathematica I can solve but I want to solve this with Matlab. > > Thanks a lot for the help ! :) > beta is build-in. Use something else. ------------------- EDU>> syms betaX EDU>> solve(tan(0.02913639281699945036921220856349)==(1-40*sin(betaX))/(40*cos(betaX)),betaX)    ans =       EDU>> double ans ans =      97 110 115 EDU>> ------------------------ Nasser
 Subject: Solving a (complicated) equation system From: Matt Date: 28 Jun, 2012 19:51:12 Message: 12 of 18 Thanks a lot Nasser. But how should I interpret this result (97 110 115) ? What I am looking for is an angle. :-)
 Subject: Solving a (complicated) equation system From: Nasser M. Abbasi Date: 28 Jun, 2012 20:01:57 Message: 13 of 18 On 6/28/2012 2:51 PM, Matt wrote: > Thanks a lot Nasser. But how should I interpret this result (97 110 115) ? What I am looking for is an angle. :-) > try this: EDU>> solve(tan(0.02913639281699945036921220856349)-(1-40*sin(betaX))/(40*cos(betaX)))    ans =    EDU>> double(ans) ans =    -0.0041 + 0.0000i     3.0875 + 0.0000i EDU>> real(ans) ans =     -0.0041      3.0875 So that is the solution. in radians. 2 angles. --Nasser
 Subject: Solving a (complicated) equation system From: Matt Date: 29 Jun, 2012 11:39:06 Message: 14 of 18 Thank you, that's the values I was looking for ! :-)
 Subject: Solving a (complicated) equation system From: Matt Date: 1 Jul, 2012 20:01:09 Message: 15 of 18 One more question : How can I automatically take the first value ? In this case the smallest one (-0.0041). I have to make calculations with this value. Thanks a lot ! :-)
 Subject: Solving a (complicated) equation system From: Nasser M. Abbasi Date: 2 Jul, 2012 01:50:12 Message: 16 of 18 On 7/1/2012 3:01 PM, Matt wrote: > One more question : > > How can I automatically take the first value ? In this case the smallest >one (-0.0041). I have to make calculations with this value. > > Thanks a lot ! :-) > use min()? syms x EDU>> sol=solve(tan(0.02913639281699945036921220856349)-(1-40*sin(x))/(40*cos(x))); EDU>> sol=double(sol); EDU>> sol=real(sol); EDU>> sol_small=min(sol) sol_small =     -0.0041 EDU>> sol_large=max(sol) sol_large =      3.0875
 Subject: Solving a (complicated) equation system From: Matt Date: 2 Jul, 2012 19:28:14 Message: 17 of 18 Yes it is just what I figured out few minutes ago ! But you have been of a very good help Nasser ! Thanks a lot ! :-)
 Subject: Solving a (complicated) equation system From: Greg Heath Date: 3 Jul, 2012 08:59:07 Message: 18 of 18 "Matt" wrote in message ... > I've converted my equation to radians : > > solve(tan(0.02913639281699945036921220856349)==(1-40*sin(beta))/(40*cos(beta)),beta) Although the equations tan(A)*R*cos(x) = E R*sin(x) = G-E Can be reduced to tan(A) = (G-R*sin(x)/(R*cos(x) They can also be reduced to sin(x+A) = G*cos(A)/R which leads to the simple solution x = - A + asin( G * cos( A ) / R ) Hope this helps. Greg Greg

## Tags for this Thread

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.