solve trigonometrical equations with input range

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)

 採用された回答

Stephan
Stephan 2019 年 2 月 2 日

2 投票

Hi,
fsolve solves nonlinear systems. sind and cosd accept degrees as input arguments. Define your system like shown in the examples for fsolve and use a for loop to calculate the solutions for every needed value of alfa.
Best regards
Stephan

23 件のコメント

pablolama
pablolama 2019 年 2 月 2 日
can't you help me to write the code?
I0m not very able wuth Matlab,
Thanks a lot
Stephan
Stephan 2019 年 2 月 2 日
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
John D'Errico 2019 年 2 月 2 日
+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
John D'Errico 2019 年 2 月 2 日
@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
madhan ravi
madhan ravi 2019 年 2 月 2 日
Why ? see stephens answer carefully.
pablolama
pablolama 2019 年 2 月 2 日
I've used fsolve now... where i insert for loop?
John D'Errico
John D'Errico 2019 年 2 月 2 日
編集済み: John D'Errico 2019 年 2 月 2 日
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
pablolama 2019 年 2 月 2 日
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
pablolama 2019 年 2 月 2 日
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
Stephan 2019 年 2 月 2 日
編集済み: Stephan 2019 年 2 月 2 日
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
pablolama 2019 年 2 月 2 日
編集済み: pablolama 2019 年 2 月 2 日
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
Stephan 2019 年 2 月 2 日
This will only use alfa at the index 14. You get one result. Where is the for loop?
pablolama
pablolama 2019 年 2 月 2 日
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
pablolama 2019 年 2 月 2 日
編集済み: pablolama 2019 年 2 月 2 日
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
Stephan 2019 年 2 月 2 日
it depends on how you saved them.
gamma = gamma(:,2)
for example if you saved gamma as a 28x2 array.
pablolama
pablolama 2019 年 2 月 2 日
編集済み: pablolama 2019 年 2 月 2 日
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
Stephan 2019 年 2 月 2 日
編集済み: Stephan 2019 年 2 月 2 日
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
madhan ravi 2019 年 2 月 2 日
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
pablolama 2019 年 2 月 2 日
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
Stephan
Stephan 2019 年 2 月 2 日
quick and dirty:
gamma(1:3,:)=-gamma(1:3,:)
pablolama
pablolama 2019 年 2 月 2 日
<3
pablolama
pablolama 2019 年 2 月 3 日
Hi starting from this code, i have to derive equations to time, to find angular velocity...
Shoul i use DIFF command?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2019 年 2 月 2 日

コメント済み:

2019 年 2 月 3 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by