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)
采纳的回答
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)
