You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
solve trigonometrical equations with input range
1 view (last 30 days)
Show older comments
How to solve on matlab this system trignometric? I need the code
1.42*cos(alfa)+3.3*cos(beta)+3.33*cos(gamma)-6= 0
1.42*sin(alfa)+3.3*sin(beta)+3.33*sin(gamma)=0
with alfa=linspace(19.7, -103, 14)
(19.7 and 103 are in degrees)
Accepted Answer
Stephan
on 2 Feb 2019
23 Comments
pablolama
on 2 Feb 2019
can't you help me to write the code?
I0m not very able wuth Matlab,
Thanks a lot
Stephan
on 2 Feb 2019
This is not the way things work here. Provide your attempts so far an ask a specific question to the problems you have by trying on your own.
John D'Errico
on 2 Feb 2019
+1. Stephan is right on the money here. You don't learn MATLAB when someone gives you a complete answer that solves your problem. The main thing you do learn then is how to ask a question so that someone will do your thinking for you, the next time you find yourself even slightly over your head.
John D'Errico
on 2 Feb 2019
@Pablolama - Please don't add an answer just to ask a question. Moved to a comment:
Why it doesn't work?
OA=1.42
AB=4.3
BO=3.33
oo=6
alfa=linspace(19.7, -103, 14)
syms OA AB alfa BO beta gamma
Result=solve(OA*cosd(alfa)+AB*cosd(beta)+BO*cosd(gamma)-OO==0),...
OA*sind(alfa)+AB*sind(beta)+BO*sind(gamma)==0,beta,gamma
Result.beta
Result.gamma
John D'Errico
on 2 Feb 2019
Edited: John D'Errico
on 2 Feb 2019
It fails first, because you overwrote all of your variables.
OA=1.42
AB=4.3
BO=3.33
oo=6
alfa=linspace(19.7, -103, 14)
syms OA AB alfa BO beta gamma
so you created OA, AB, BO as double precision numbers. Then you re-defined them, when you created them as syms. The values they originally had when you created them? Those numbers diasppeared.
OA
OA =
OA
So now, OA, AB, and BO are all gone, turned into purely symbolic unknowns.
Next, you defined the variable oo. But then you use the variable OO.
And finally, you had a right parens in thewrong place.
OO= 6;
Result=solve(OA*cosd(alfa)+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa)+AB*sind(beta)+BO*sind(gamma)==0,beta,gamma);
Basically, you need to learn to be more careful in your typing.
pablolama
on 2 Feb 2019
This is correct?
OA=1.42
AB=4.3
BO=3.33
OO=6
alfa=linspace(19.7, -103, 14)
Result=fsolve(OA*cosd(alfa)+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa)+AB*sind(beta)+BO*sind(gamma)==0,beta,gamma);
Result.beta
Result.gamma
pablolama
on 2 Feb 2019
Thanks but when i insert:
OA=1.42
AB=4.3
BO=3.33
OO=6
alfa=linspace(19.7, -103, 14)
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa(k))+AB*sind(beta)+BO*sind(gamma)==0],beta,gamma);
i have:
Undefined function or variable 'k'.
Error in Untitled (line 8)
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
Stephan
on 2 Feb 2019
Edited: Stephan
on 2 Feb 2019
it is the counter variable of my for loop. Since you did not define a for loop there is an error message.
With every call of fsolve (or solve) i can get a solution for ONE discrete value of alfa. So the for loop should call fsolve (or solve) as often as there are different values for alfa to solve for.
pablolama
on 2 Feb 2019
Edited: pablolama
on 2 Feb 2019
I've known the concept of for loop. In my case there are 14 repetitions... I'm not sure where and how to insert k=14
OA=1.42
AB=4.3
BO=3.33
OO=6
alfa=linspace(19.7, -103, 14)
k=14
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa(k))+AB*sind(beta)+BO*sind(gamma)==0],beta,gamma);
Stephan
on 2 Feb 2019
This will only use alfa at the index 14. You get one result. Where is the for loop?
pablolama
on 2 Feb 2019
It is right this?
OA=1.42
AB=4.3
BO=3.33
OO=6
alfa=linspace(19.7, -103, 14)
for k=1:14
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa(k))+AB*sind(beta)+BO*sind(gamma)==0],beta,gamma);
end
pablolama
on 2 Feb 2019
Edited: pablolama
on 2 Feb 2019
Thanks man i've solved:
I have 28 results for beta and 28 results for gamma.
How can i select only the second of every results:
(360*atan((3*231145121043063523048193884227692741963912548529193598661322470324485271^(1/2))/3895915006802471275548707707929850169 + 448193734313188167693069702922240000/3895915006802471275548707707929850169))/pi
-(360*atan((3*231145121043063523048193884227692741963912548529193598661322470324485271^(1/2))/3895915006802471275548707707929850169 - 448193734313188167693069702922240000/3895915006802471275548707707929850169))/pi
Stephan
on 2 Feb 2019
it depends on how you saved them.
gamma = gamma(:,2)
for example if you saved gamma as a 28x2 array.
madhan ravi
on 2 Feb 2019
pablolama
on 2 Feb 2019
Edited: pablolama
on 2 Feb 2019
I'm really getting mad
2 minutes ago my code worked...
Now the same code pasted, doesn't work.
Suggest?
OA=1.42
AB=4.3
BO=3.33
OO=6
alfa=linspace(19.7, -103, 14)
for k=1:14
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa(k))+AB*sind(beta)+BO*sind(gamma)==0],beta,gamma);
end
Not enough input arguments.
Error in beta (line 19)
y = exp(betaln(z,w));
Error in Untitled2222 (line 5)
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
Stephan
on 2 Feb 2019
Edited: Stephan
on 2 Feb 2019
syms beta gamma
OA=1.42;
AB=4.3;
BO=3.33;
OO=6;
alfa=linspace(19.7, -103, 14);
% preallocate solution arrays
result_beta = nan(numel(alfa),2);
result_gamma = nan(numel(alfa),2);
% solve and save the results
for k = 1:numel(alfa)
[res_beta, res_gamma]=solve([OA*cosd(alfa(k))+AB*cosd(beta)+BO*cosd(gamma)-OO==0,...
OA*sind(alfa(k))+AB*sind(beta)+BO*sind(gamma)==0],beta,gamma);
result_beta(k,:)=double(res_beta);
result_gamma(k,:)=double(res_gamma);
end
madhan ravi
on 2 Feb 2019
In your mind you know what is beta but matlab doesn’t know that so you have to tell it to matlab in the proper manner.
pablolama
on 2 Feb 2019
One questions:
in results, i have:
It's evident that the first three rows are inverted (first column must be all negative, second all positive).... That it beacause of the angles and the equations. There is a way to invert them?
thanks
56.3136 -68.0355
60.0422 -66.3337
63.3157 -63.8261
-60.6513 65.9511
-56.9882 67.8010
-53.0279 68.7742
-48.9467 68.8414
-44.8871 68.0280
-40.9515 66.3985
-37.2048 64.0403
-33.6824 61.0509
-30.3996 57.5285
-27.3598 53.5685
-24.5623 49.2618
pablolama
on 3 Feb 2019
Hi starting from this code, i have to derive equations to time, to find angular velocity...
Shoul i use DIFF command?
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)