solve trigonometrical equations with input range
3 次查看(过去 30 天)
显示 更早的评论
pablolama
2019-2-2
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
2019-2-2
23 个评论
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
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
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
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
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
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
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
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
2019-2-2
This will only use alfa at the index 14. You get one result. Where is the for loop?
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
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
2019-2-2
it depends on how you saved them.
gamma = gamma(:,2)
for example if you saved gamma as a 28x2 array.
madhan ravi
2019-2-2
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
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
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
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
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)