High order equation Solving

1 visualizzazione (ultimi 30 giorni)
Jack_111
Jack_111 il 11 Ott 2013
Commentato: Walter Roberson il 14 Ott 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

Risposta accettata

sixwwwwww
sixwwwwww il 12 Ott 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 Commenti
Jack_111
Jack_111 il 14 Ott 2013
But the answer still in the Subbolic way and I want it in the double format or float
Walter Roberson
Walter Roberson il 14 Ott 2013
double(Solution)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by