solve trigonometrical equations with input range
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
can't you help me to write the code?
I0m not very able wuth Matlab,
Thanks a lot
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.
+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.
@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
Why ? see stephens answer carefully.
I've used fsolve now... where i insert for loop?
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.
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
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,...
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.
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);
This will only use alfa at the index 14. You get one result. Where is the for loop?
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
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
it depends on how you saved them.
gamma = gamma(:,2)
for example if you saved gamma as a 28x2 array.
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,...
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
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.
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
quick and dirty:
gamma(1:3,:)=-gamma(1:3,:)
<3
Hi starting from this code, i have to derive equations to time, to find angular velocity...
Shoul i use DIFF command?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
