Complex Number Issue
Ältere Kommentare anzeigen
I'm working on an image processing problem that keeps giving me a complex number. Is it possible to get this number in some useable form? If I solve the problem in mathematica i get s approches 0. Please see code below. I'm getting an imaginary number on spos and sneg.
Xell = (P1(1)-(XSize/2))*pixelSx; %-0.2182 Xelr = (P2(1)-(XSize/2))*pixelSx; %-.0269 Xerl = (P4(1)-(XSize/2))*pixelSx; %.8085 Xerr = (P5(1)-(XSize/2))*pixelSx; %1.0348
% Yaw (The Rotation Angle of Y-Axis, Beta)
I2 = (((Xerl - Xerr)*(Xell - Xelr))/((Xell - Xerl)*(Xelr - Xerr))) Q = 1/sqrt(I2)-1; M = -1/(2+Q);
u_num = ((Xell - Xelr)*(Xerl - Xerr)*M*(Xelr - Xerl)-(M)^2*(Xell - Xerr)*(Xelr - Xerl)^2); u_div = ((Xell - Xelr)*(M*(Xelr - Xerl) - (Xerl - Xerr))); u = u_num/u_div;
spos = (Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr); sneg = -(Xelr - Xell + Xerl - Xerr - Q*Xell + Q*Xelr + Q*Xerl - Q*Xerr + (4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2))/(Q*Xell - Q*Xelr + Q*Xerl - Q*Xerr);
Beta0neg = atand(f/((sneg-1)*u)); Beta0pos = atand(f/((spos-1)*u));
1 Kommentar
David Young
am 11 Feb. 2011
It's a good idea to mark code as such, either by indenting it, or by selecting it and using the "{} code" button. Otherwise it gets wrapped, the questions is hard to read, and you have to reinsert line breaks if you copy the code.
Akzeptierte Antwort
Weitere Antworten (3)
Mark
am 11 Feb. 2011
1 Kommentar
David Young
am 11 Feb. 2011
Thanks! But even better to edit the question!
Walter Roberson
am 11 Feb. 2011
The subexpression
(4*Q^2*Xell*Xerr - 4*Q^2*Xell*Xerl + 4*Q^2*Xelr*Xerl - 4*Q^2*Xelr*Xerr - 8*Q*Xell*Xerl + 8*Q*Xell*Xerr + 8*Q*Xelr*Xerl - 8*Q*Xelr*Xerr + Xell^2 - 2*Xell*Xelr - 2*Xell*Xerl + 2*Xell*Xerr + Xelr^2 + 2*Xelr*Xerl - 2*Xelr*Xerr + Xerl^2 - 2*Xerl*Xerr + Xerr^2)^(1/2)
corresponds to the sqrt(b^2-4*a*c) term of a quadratic. Strip off the ^(1/2) layer and evaluate the subexpression. With the values you have provided, it comes out as -4.1857998 so naturally you will get a complex number in evaluation of both spos and sneg.
If you go back to your original question and substitute in those numeric values together with the expression you give here for "Q" as the value of "q" in that question, you end up with asking to solve
.8453380468 = -(s-1)*(s-1.497771143)/((s+1)*(s+1.497771143))
If you set aside the leading negative for a moment, you can see this is the ratio of two parabolas that are both open upwards and that are mirror images around x=0. The two will have different signs only in the neighbourhood +/- (1, 1.497771143) and so for most values of s, the ratio will be positive. But that positive number is negated by the leading negative, so for most real values of s, the expression as a whole will be negative. You are trying to solve a positive value equaling an expression that is usually negative in reals. It should therefore be considered to be quite plausible that there is no real valued solution.
If you go back to your original question but leave q undefined for a moment, and drop in the other values you give here, then solve for s, and examine the conditions under which that s will be real-valued, you find you need -2.113345117*10^11*q^2-4.226690234*10^11*q+1.495019985*10^9 to be non-negative. That occurs in the range q = (-2.003530860, 0.003530860320) . If you then evaluate the formula for Q that you give in this posting, using the numeric values you supplied, then you will find Q = 4.017910695 which is well outside the range of solution.
Therefor, unless your expression for Q is quite wrong, you are not going to be able to come up with a real-valued solution for this problem.
Mark
am 11 Feb. 2011
3 Kommentare
Walter Roberson
am 11 Feb. 2011
Using those equations and substituting in the values for the first three variables, leaving Xerr undefined, the solutions for s have two distinct portions involving square roots of expressions involving Xerr. The simpler of those expressions is linear and has a zero at Xerr = 1617/2000 (about 0.8085), below which that portion goes complex. The more complicated of the square roots is of a cubic in Xerr, which starts negative and has zeros at 0.05112649564, .8085000008, and 5.290073503. The .8085 value is exactly that same 1617/2000, *above* which the expression goes negative until Xerr reaches 5.290073503. So one goes complex below 1617/2000 and the other goes complex above 1617/2000, until about 5. Thus there are real-valued (negative) solutions for s when Xerr = 1617/2000 _exactly_ (given the other constants), or when Xerr exceeds that 5-ish number. With your Xerr just over 1, the solutions must be complex.
I guess it might not be impossible for the complex parts of the expression to exactly cancel out somewhere between 0.05 and 1617/2000, but it would be just at a point at best.
Either your constants are not in an acceptable range or your equations are not what is in the paper, or the paper is wrong.
Do you have a URL for the paper (free download) ?
Mark
am 11 Feb. 2011
Mark
am 11 Feb. 2011
Kategorien
Mehr zu GenICam Interface finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!