which solver is best to solve a set of trig equation?

2 visualizzazioni (ultimi 30 giorni)
I wonder if existing MATLAB solvers can solve my set of trignometric equations:
For the above equations, assume I know , , , and , and I want to solve for θ and ϕ.
I tried using fsolve with 2 and 3 equations but the solutions I got was incorrect:
%test
lambda = 0.06;
azi = 36;
ele = 55;
%DOA= [azi ele];
x1 = 0.06; y1 = 0 ; z1 = 0;
x2 = 0.12; y2 = 0; z2 = 0;
x3 = 0.06; y3 = 0.06; z3 = 0;
s1 = exp((2*pi*1j)*((x1*cosd(azi)*sind(ele)+y1*sind(azi)*sind(ele)+z1*cosd(ele))/lambda))
s1 = -0.5214 - 0.8533i
s2 = exp((2*pi*1j)*((x2*cosd(azi)*sind(ele)+y2*sind(azi)*sind(ele)+z2*cosd(ele))/lambda))
s2 = -0.4563 + 0.8898i
s3 = exp((2*pi*1j)*((x3*cosd(azi)*sind(ele)+y3*sind(azi)*sind(ele)+z3*cosd(ele))/lambda))
s3 = 0.6169 + 0.7870i
%now, work backward, use s1 and s2 ro find azi and ele, still try to use
%fsolve
leftside1 = real(log(s1)/(2*pi*1j)) %solution contains imaginary value == 0i
leftside1 = -0.3373
leftside2 = real(log(s2)/(2*pi*1j))
leftside2 = 0.3254
leftside3 = real(log(s3)/(2*pi*1j))
leftside3 = 0.1442
((x1*cosd(azi)*sind(ele)+y1*sind(azi)*sind(ele)+z1*cosd(ele))/lambda)-leftside1
ans = 1
((x2*cosd(azi)*sind(ele)+y2*sind(azi)*sind(ele)+z2*cosd(ele))/lambda)-leftside2
ans = 1
((x3*cosd(azi)*sind(ele)+y3*sind(azi)*sind(ele)+z3*cosd(ele))/lambda)-leftside3
ans = 1
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt,'Algorithm','levenberg-marquardt')
options =
fsolve options: Options used by current Algorithm ('levenberg-marquardt'): (Other available algorithms: 'trust-region', 'trust-region-dogleg') Set properties: Algorithm: 'levenberg-marquardt' Display: 'none' PlotFcn: @optimplotfirstorderopt Default properties: CheckGradients: 0 FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e-06 MaxFunctionEvaluations: '200*numberOfVariables' MaxIterations: 400 OutputFcn: [] SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e-06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0 Show options not used by current Algorithm ('levenberg-marquardt')
fun = @(DOA)f_angle(DOA,leftside1,leftside2,leftside3);
DOA0 = [35,54];
DOA = fsolve(fun,DOA0,options)
Error using uicontrol
This functionality is not available on remote platforms.

Error in callAllOptimPlotFcns (line 78)
stopBtn = uicontrol('string',getString(message('MATLAB:optimfun:funfun:optimplots:ButtonStop')), ...

Error in levenbergMarquardt>callOutputAndPlotFcns (line 437)
stop = callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:}) || stop;

Error in levenbergMarquardt (line 147)
[optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,caller,reshape(XOUT,xShape),...

Error in fsolve (line 450)
levenbergMarquardt(funfcn,x,lb,ub,verbosity,options,defaultopt,f,JAC,caller, ...
function f = f_angle(DOA,leftside1,leftside2,leftside3)
lambda = 0.06;
x1 = 0.06; y1 = 0 ; z1 = 0;
x2 = 0.12; y2 = 0; z2 = 0;
x3 = 0.06; y3 = 0.06; z3 = 0;
f(1)= ((x1*cosd(DOA(1))*sind(DOA(2))+y1*sind(DOA(1))*sind(DOA(2))+z1*cosd(DOA(2)))/lambda) -leftside1;
f(2)= ((x2*cosd(DOA(1))*sind(DOA(2))+y2*sind(DOA(1))*sind(DOA(2))+z2*cosd(DOA(2)))/lambda) -leftside2;
f(3)= ((x3*cosd(DOA(1))*sind(DOA(2))+y3*sind(DOA(1))*sind(DOA(2))+z3*cosd(DOA(2)))/lambda) -leftside3;
end
my intended angle is [36 55] but fsolve returns [52.4154 5.9013].
Ultimately, my value would contain some small noise so equal sign would turn into an approx equal sign so I think symbolic solver would be in no use.
Would be nice to know whether this set of equations are solvable using MATLAB? If so which solver/set up should I be looking into?
Thanks
  2 Commenti
Torsten
Torsten il 20 Ago 2022
As you can see above, f(1) = f(2) = f(3) = 1, not 0.
Xingda Chen
Xingda Chen il 20 Ago 2022
Modificato: Xingda Chen il 20 Ago 2022
Hi Torsten,
Yes I realized I cannot simiply log a complex number. I am editing my script such that my a+bj complex number returns a phase reading in term of degrees/radians, and then re-run fsolve and see if that works

Accedi per commentare.

Risposta accettata

Xingda Chen
Xingda Chen il 21 Ago 2022
Modificato: Xingda Chen il 21 Ago 2022
I realized I cannot simiply log a complex number. I am editing my script such that my a+bj complex number returns an angle reading in term of degrees/radians, as well as making sure the returned phase isn't wrap within 2*pi. fsolve() proudly completed the job.... kudos to the team who developed fsolve()!

Più risposte (0)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by