High order equation Solving

4 views (last 30 days)
Jack_111
Jack_111 on 11 Oct 2013
Commented: Walter Roberson on 14 Oct 2013
I am doing ray tracing and I have to make intersection between the ray and polynomial so I got the following equation and I have to solve it for t.
A(21).*(Y.^5) + (A(20).*(Y.^4)).*X + A(19).*(Y.^4) + (A(18).*(Y.^3)).*(X.^2) + (A(17).*(Y.^3)).*X + A(16).*(Y.^3) + (A(15).*(Y.^2)).*(X.^3) + (A(14).*(Y.^2)).*(X.^2) + (A(13).*(Y.^2)).*X + A(12).*(Y.^2) + (A(11).*(Y)).*(X.^4) + (A(10).*Y).*(X.^3) + (A(9).*Y).*(X.^2) + (A(8).*Y).*(X) + (A(7).*Y) + A(6).*(X.^5) + A(5).*(X.^4) + A(4).*(X.^3) + A(3).*(X.^2) + A(2).*X + A(1) - Z = 0;*
While:
X = (px +t*dx);
Y = (py +t*dy);
Z = (pz +t*dz);
so I want to get t in respect to the other variables. ( I have all the other variables but I don't know how to calculate it )
Please support Many thanks in advance

Accepted Answer

sixwwwwww
sixwwwwww on 12 Oct 2013
Dear Yaman, Here is the solution of your problem in symbolic form:
syms X Y Z p x y z t dx dy dz
A = sym('A%d', [1 21]);
X = p * x + t * dx;
Y = p * y + t * dy;
Z = p * z + t * dz;
equation = A(21) * Y^5 + (A(20) * Y^4) * X + A(19)* Y^4 + (A(18) * Y^3) * X^2 + (A(17) * Y^3) * X + A(16) * Y^3 + (A(15) * Y^2) * X^3 + ...
(A(14) * Y^2) * X^2 + (A(13) * Y^2) * X + A(12) * Y^2 + (A(11) * Y) * X^4 + (A(10) * Y) * X^3 + (A(9) * Y) * X^2 + (A(8) * Y) *X + A(7) * Y +...
A(6) * X^5 + A(5) * X^4 + A(4) * X^3 + A(3) * X^2 + A(2) * X + A(1) - Z;
Solution = solve(equation == 0, t);
Now if you put your know values of A(1)...A(21) and p, x, y, z, dx, dy, dz using "subs" function in "equation" then use last statement
Solution = solve(equation == 0, t);
then you will get your desired solution for "t". For information about "subs" see http://www.mathworks.com/help/symbolic/subs.html . Good luck!
  2 Comments
Walter Roberson
Walter Roberson on 14 Oct 2013
double(Solution)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!