14 views (last 30 days)

Show older comments

I am trying to solve the following set of matrix equations

The values of r1, r2, r3 and ψare known. The values of θ and ϕ are to be found by solving this equation in matlab. i attempt to do this using the fsolve function. However, it is not able to arrive to a solution. Is there a better way to solve this?

function F = root2d(Ficksang)

rfinal = [0,-0.101233861621737,0.365119069777688];

theta_f = Ficksang(1);

phi_f = Ficksang(2);

psi_f = 0;

r1 = rfinal(1);

r2 = rfinal(2);

r3 = rfinal(3);

F(1) = r1 - ( ( tan(psi_f/2) - (tan(theta_f/2) * tan(phi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

F(2) = r2 - ( ( tan(phi_f/2) + (tan(theta_f/2) * tan(psi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

F(3) = r3 - ( ( tan(theta_f/2) - (tan(phi_f/2) * tan(psi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

fun = @root2d;

x0 = [0,0];

x = fsolve(fun,x0)

Matt J
on 20 Sep 2021

Edited: Matt J
on 20 Sep 2021

With an over-determined system (3 equations and only 2 unknowns), you can't expect an exact solution. However, the solution that fsolve does find does seem to be valid as a least squares solution, judging from the surface plot below.

fun = @root2d;

x0 = [0,0];

[x,f] = fsolve(fun,x0);

x

[Theta,Phi]=ndgrid( linspace(-pi/2,pi/2,300));

fun=@(x,y)norm(root2d([x,y]));

F= arrayfun(fun,Theta,Phi);

surf(Theta,Phi,F,'EdgeColor','none')

xlabel 'Theta', ylabel 'Phi'

view(60,65)

Sargondjani
on 20 Sep 2021

Your method seems valid. But of course fsolve will only attempt to find a local solution, and it might get stuck in a place where there is locally no solution.

Did you try with other starting values? This might work in general if you know where your solutions should approximately be.

Walter Roberson
on 20 Sep 2021

Optimal solutions, in the sense of smallest least-squared.

Are there other solutions? Yes: you can ask to solve eqn2 with return conditions set, and the answer will be parameterized . One of the variables of parameterization, k will add multiples of pi .

(The other one is a nuisance variable -- the expression inside the root() is pulled out into a parameterized variable and the "conditions" are that the fifth degree polynomial = 0. And then to express F2 you have to extract the expression from the conditions and wrap it with a root() yourself... Do-able, but a nuisance.)

format long g

syms F [1 2]

fun = root2d(F);

residue = sum(fun.^2)

bestF1 = solve(diff(residue, F(1)),F(1))

eqn2 = subs(residue, F(1), bestF1)

sol2 = solve(diff(eqn2, F(2)),F(2));

F2 = sol2;

F1 = subs(bestF1, F(2), F2);

F1

F2

F1n = double(F1)

F2n = double(F2)

function F = root2d(Ficksang)

rfinal = [0,-0.101233861621737,0.365119069777688];

theta_f = Ficksang(1);

phi_f = Ficksang(2);

psi_f = 0;

r1 = rfinal(1);

r2 = rfinal(2);

r3 = rfinal(3);

F(1) = r1 - ( ( tan(psi_f/2) - (tan(theta_f/2) * tan(phi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

F(2) = r2 - ( ( tan(phi_f/2) + (tan(theta_f/2) * tan(psi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

F(3) = r3 - ( ( tan(theta_f/2) - (tan(phi_f/2) * tan(psi_f/2)) ) / ...

( 1 + (tan(theta_f/2) * tan(phi_f/2) * tan(psi_f/2)) ) );

end

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

Start Hunting!