How to solve simultaneous equation with trigonometric function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello, any one can help me
syms alpha gamma R d
R = 0.08;
d = 1.4;
R^2 == 4*(alpha)^2 / [(2*(alpha)^2 + 1) * acos*(2*gamma) + (2*(alpha)^2 - 1) * cos*(2*gamma) + 2*alpha*(asin*(2*gamma)) - sin*(2*gamma)]
d == atan*[(atan(2*alpha*tan*gamma + 1) + tan*gamma) / (tan*gamma - atan*gamma + 2*alpha)]
sol = solve ([R^2, d] , [alpha, gamma])
alphaSol = sol.alpha
gammaSol = sol.gamma
I need to obtain alpha and gamma
There is : Error using acos
Not enough input arguments.
- if I delete acos, another error is appear (cos, ect)
채택된 답변
KSSV
2022년 7월 26일
You cannot write acos*(2*gamma) and tan*gamma. Note that they are function and they need someinput. It migh be: acos(2*gamma) and tan(gamma)
syms alpha gamma R d
R = 0.08;
d = 1.4;
R^2 == 4*(alpha)^2 / ((2*(alpha)^2 + 1) * acos(2*gamma) + (2*(alpha)^2 - 1) * cos(2*gamma) + 2*alpha*(asin(2*gamma)) - sin(2*gamma))
d == atan((atan(2*alpha*tan(gamma) + 1) + tan(gamma)) / (tan(gamma) - atan(gamma) + 2*alpha))
sol = solve ([R^2, d] , [alpha, gamma])
alphaSol = sol.alpha
gammaSol = sol.gamma
Though the above is not giving any solution, you need to check your expression properly.
댓글 수: 17
I already mentioned that. Check your expression. REad about solve. You can give some assumptions to your solution if you have.
syms alpha gamma %R d
R = 0.08;
d = 1.4;
expr1 = R^2 == 4*(alpha)^2 / ((2*(alpha)^2 + 1) * acos(2*gamma) + (2*(alpha)^2 - 1) * cos(2*gamma) + 2*alpha*(asin(2*gamma)) - sin(2*gamma))
expr1 =

expr2 = d == atan((atan(2*alpha*tan(gamma) + 1) + tan(gamma)) / (tan(gamma) - atan(gamma) + 2*alpha))
expr2 =
sol = solve ([expr1,expr2] , [alpha, gamma])
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
sol = struct with fields:
alpha: 0.89004376539962278983379602051241 + 0.38919789229051247720270451525197i
gamma: 78.222544477417321649984876860727 - 3.0960897467326888301848990655128i
alphaSol = sol.alpha
alphaSol = 
gammaSol = sol.gamma
gammaSol = 
Dear @Torsten
I apologize in advance, it looks like I made a mistake by writing the equation at first.
The equation I mean as attached,
I don't know why I can't check it into that form.
If you don't mind, can you check my writing equation :
expr1 = (R)^2 == 4*(alpha)^2 / (2*(alpha)^2 + 1) * acos(2*gamma) + ((2*(alpha)^2 - 1) * cos(2*gamma)) + (2*alpha*(asin(2*gamma) - sin(2*gamma)))
is it same with the attached equation or not, please?
If I use live editor with latex equation, it's same,
|R|^2 = \dfrac{4\alpha^2} {(2\alpha^2 + 1) cosh 2\gamma + (2\alpha^2 - 1) cos 2\gamma + 2\alpha (sinh 2\gamma - sin 2\gamma)}
but I haven't been successful to use it in the live editor, so I wrote it manually.
Thank you in advance
Note that tanh, sinh and cosh are the hyperbolic tangent, hyperbolic sine and hyperbolic cosine, not atan, asin and acos which are the inverse tangent, inverse sin and inverse cosine functions.
syms alpha gamma %R d
R = 0.08;
d = 1.4;
expr1 = R^2 == 4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma)))
expr1 =

expr2 = d == atan((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))
expr2 =
sol = solve ([expr1,expr2] , [alpha, gamma])
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
sol = struct with fields:
alpha: 0.74245496926973860397234179524781
gamma: 2.627014792787395537585234942901
alphaSol = sol.alpha
alphaSol =
0.74245496926973860397234179524781
gammaSol = sol.gamma
gammaSol =
2.627014792787395537585234942901
Thank you so much @Torsten
I still trying for others R and d values,
R = 0.022 to 0.12
d = 60 to 150
but the results are :
alphaSol = Empty sym: 0-by-1
gammaSol = Empty sym: 0-by-1
If I read, they said it might be because there isn't any solution to the equation
atan is between -pi/2 and pi/2. So I don't understand how "d" could be between 60 and150 - except you want to get complex solutions, maybe.
actually d is phase difference in degree
Last time I use in radians, but it should be in degree
In your test equation, d was 7/5 which does not seem to be in degrees.
However: if you want to prescribe d in degrees, change
expr2 = d == atan((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))
to
expr2 = d == atand((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))
I already tried that one @Torsten
I checked with substituting R = 0.07 and d = -135, they will give alpha = 0.15 and gamma 1.7
but, the results still
alphaSol =
Empty sym: 0-by-1
gammaSol =
Empty sym: 0-by-1
:((((((
Your equations cannot be solved symbolically for alpha and gamma. That's why MATLAB uses vpasolve to return a numerical solution.
I tried :
%%
syms alpha gamma %R d
R = 0.07;
d = -135;
[sol_alpha, sol_gamma] = vpasolve([(R)^2 == 4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma))), d == atand((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))], [alpha,gamma])
But :
- Undefined function 'atand' for input arguments of type 'sym'.
then, when I change atand to atan back to eror : sol_alpha = Empty sym: 0-by-1 ; sol_gamma = Empty sym: 0-by-1
Hi, Christina, if your equations are:
R = 0.08;
d = 1.4;
R^2 == 4*(alpha)^2 / ((2*(alpha)^2 + 1) * acos(2*gamma) + (2*(alpha)^2 - 1) * cos(2*gamma) + 2*alpha*(asin(2*gamma)) - sin(2*gamma))
d == atan((atan(2*alpha*tan(gamma) + 1)+ tan(gamma)) / (tan(gamma) - atan(gamma) + 2*alpha))
The results will be:
alpha: 0.0503567460786745
gamma: -0.234530822330344
While if your eauqtions are:
R = 0.08;
d = 1.4;
R^2 == 4*(alpha)^2 / ((2*(alpha)^2 + 1) * acos(2*gamma) + (2*(alpha)^2 - 1) * cos(2*gamma) + 2*alpha*(asin(2*gamma)) - sin(2*gamma))
(R)^2 == 4*(alpha)^2 / (2*(alpha)^2 + 1) * acos(2*gamma) + ((2*(alpha)^2 - 1) * cos(2*gamma)) + (2*alpha*(asin(2*gamma) - sin(2*gamma)))
then there will not be solution in real data type
Thank you for your comment @Alex Sha
I run code :
%%
syms alpha gamma %R d
R = 0.07;
d = -135;
expr1 = (R)^2 == 4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma)))
expr2 = d == atan((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))
sol = solve ([expr1,expr2] , [alpha, gamma])
alphaSol = sol.alpha
gammaSol = sol.gamma
also :
%%
syms alpha gamma %R d
R = 0.07;
d = -135;
[sol_alpha, sol_gamma] = vpasolve([(R)^2 == 4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma))), d == atand((tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha))], [alpha,gamma])
I tried the code by substituting R (0.07) and d (-135 in degress) to check my code, it should be give alpha = 0.15 and gamma = 1.7
But still gives an errors
Take the tand out of both sides of the second equation, so
tand(d) == tand(atand(Expression))
and simplify to
tand(d) == Expression
it makes it easier for vpasolve to find solutions
Seems there are several solutions to your equations:
R = 0.07;
d = -135;
fun = @(alpha,gamma)[4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma)))-R^2;...
(tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha)-tand(d)];
options = optimset('TolFun',1e-8,'TolX',1e-8);
alpha0 = 0.15;
gamma0 = 1.7;
x0 = [alpha0,gamma0];
sol = fsolve(@(x)fun(x(1),x(2)),x0,options);
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
alpha = sol(1)
alpha = 0.1786
gamma = sol(2)
gamma = 1.7811
fun(alpha,gamma)
ans = 2×1
1.0e-11 *
0.0055
-0.7673
alpha0 = -0.4;
gamma0 = -2.3;
x0 = [alpha0,gamma0];
sol = fsolve(@(x)fun(x(1),x(2)),x0,options);
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
alpha = sol(1)
alpha = -0.3679
gamma = sol(2)
gamma = -2.3475
fun(alpha,gamma)
ans = 2×1
1.0e-08 *
-0.0013
0.1872
syms alpha gamma %R d
R = 0.07;
d = -135;
expr1 = R^2 == 4*alpha^2/((2*alpha^2+1)*cosh(2*gamma)+(2*alpha^2-1)*cos(2*gamma)+2*alpha*(sinh(2*gamma)-sin(2*gamma)));
expr2 = tand(d) == (tanh(2*alpha*tan(gamma)+1)+tan(gamma))/(tan(gamma)-tanh(gamma)+2*alpha);
[sol_alpha, sol_gamma] = solve([expr1,expr2], [alpha,gamma])
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
sol_alpha = 
sol_gamma = 
fun(double(sol_alpha),double(sol_gamma))
ans = 2×1
1.0e-15 *
-0.0017
0.4441
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
참고 항목
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)
