Question

let

    n0 =

 nx*cos(a) + nz*cos(b)*sin(a) + ny*sin(a)*sin(b)
                           ny*cos(b) - nz*sin(b)
 nz*cos(a)*cos(b) - nx*sin(a) + ny*cos(a)*sin(b)

in a and b,with the ns fixed (but of course,not assigned) values. if I do

[a,b]=solve(n0-[1 0 0]',a,b,'IgnoreAnalyticConstraints',true)

i get

    Error using solve>assignOutputs (line 257)
3 variables does not match 2 outputs.

    Error in solve (line 193)
varargout = assignOutputs(nargout,sol,sym(vars));

then I wonder ''3 variables''? Then I try

>> [a,b,c]=solve(n0-[1 0 0]',a,b,'IgnoreAnalyticConstraints',true)

that's the response

a =

cos(a)/(cos(a)^2 + sin(a)^2)


b =

(sin(a)*sin(b))/((cos(a)^2 + sin(a)^2)*(cos(b)^2 + sin(b)^2))


c =

(cos(b)*sin(a))/((cos(a)^2 + sin(a)^2)*(cos(b)^2 + sin(b)^2))

what is it doing? what's in c? I suppose he's solving with respect to nx ny nz,but why?every time I try to solve a problem with n+k equation in n variables I get strange errors,even if the rank of the system is just n.

that means even a=2 b=3 a+b=5 gives me problems. how can I fix that?

Was it helpful?

Solution

I also cannot replicate the "Error in solve" error. What version of Matlab are you using? Also, I think some of the error message is missing – always list the entire error message. In any case, R2013a, solve does not find any solutions. Mathematica 9's Solve also does not find any.

I suspect why @DanielR and I can't exactly reduce your issue in the second case is that you may have a mistake in one of your lines above – it should be:

[a,b,c] = solve(n0-[1 0 0]','IgnoreAnalyticConstraints',true)

that produces

a =

cos(a)/(cos(a)^2 + sin(a)^2)


b =

(sin(a)*sin(b))/((cos(a)^2 + sin(a)^2)*(cos(b)^2 + sin(b)^2))


c =

(cos(b)*sin(a))/((cos(a)^2 + sin(a)^2)*(cos(b)^2 + sin(b)^2))

What are the outputs a, b, and c (these simplify to cos(a), sin(a)*sin(b), and sin(a)*cos(b), by the way)? A big hint is that all of the solutions are in terms of your original variables a and b, but not nx, ny, or nz. When you don't specify which variables to solve for solve picks them. If you instead return the solutions in structure form, the nature of the output is made clear:

s = solve(n0-[1 0 0]','IgnoreAnalyticConstraints',true)

s = 

    nx: [1x1 sym]
    ny: [1x1 sym]
    nz: [1x1 sym]

But I think that you probably want to solve for a and b as a function of nx, ny, and nz, not the other way around. You're not correct about using solve to find solutions to overdetermined systems. Even when you have more equations then unknowns this is not always possible with nonlinear equations. If you can introduce some assumptions or even additional equations or specify numerical values for any of the nx, ny, or nz variables, solve may be able to separate and invert the equations.

And you shouldn't really use the term "rank" except for linear systems. In the case of the linear system example that you gave solve works fine:

[a,b] = solve([a==2 b==3 a+b==5],a,b)

or

[a,b] = solve(a==2,b==3,a+b==5,a,b)

or

[a,b] = solve([1 0;0 1;1 1]*[a;b]==[2;3;5],a,b)

returns

Warning: 3 equations in 2 variables. 
> In /Applications/MATLAB_R2013a.app/toolbox/symbolic/symbolic/symengine.p>symengine at 56
  In mupadengine.mupadengine>mupadengine.evalin at 97
  In mupadengine.mupadengine>mupadengine.feval at 150
  In solve at 170 

a =

2


b =

3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top