Filter löschen
Filter löschen

How do I get the "Null" coefficients of an equation?

1 Ansicht (letzte 30 Tage)
Pedro Guevara
Pedro Guevara am 11 Jan. 2021
Good day.
I have the following concern. I have this matrix called "Nodos" that contains the coordinates of 3 points that make up a plane for me (The first 3 columns are the X, Y and Z components):
Nodos:
0 0 0 5
0 5 0 4
6 0 3 8
I am using the following code to obtain the equation of the plane:
normal = cross(Nodos(1,1:3)-Nodos(2,1:3 ), Nodos(1,1:3)- Nodos(3,1:3) );
syms xs ys zs
Pla = [xs,ys,zs];
planefunction1 = dot(normal, Pla - Nodos(1,1:3 ))
[Coe1,Var1] = coeffs(planefunction1);
However when I want to obtain the coefficients (in the last line of code I am losing the "Null" coefficient of the variable ys:
planefunction1 =15*xs - 30*zs
Does anyone know why it happens and how do I prevent that from happening?
Thanks a lot.
  1 Kommentar
David Goodmanson
David Goodmanson am 12 Jan. 2021
Hi Pedro,
are you saying that in cases like this one where there is a zero coeffiecient, you would like the result to be
planefunction1 =15*xs + 0*ys - 30*zs ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sai Sumanth Korthiwada
Sai Sumanth Korthiwada am 24 Feb. 2022
As per my understanding, the coefficient of "ys" is not being displayed when using "coeffs" function and to prevent that issue, "diff" function can be used.
Reason:
While using the "dot" function, the values in "Pla" gets multiplied with "normal". During the dot product of two vectors "Pla" and "normal", as the value corresponding to "ys" is 0, it gets multiplied i.e., 0*ys along with 15*xs and –30*zs. As a result, the output only shows 15xs-30zs instead of 15xs+0ys-30zs.
Solution:
To obtain the coefficients of all the variables in a multi-variable linear equation, use "diff" function which differentiates the equation with respect to a variable. The modified code which resolves the issue and displays the coefficients of "xs", "ys", "zs" is displayed below:
Nodos = [0 0 0 5; 0 5 0 4; 6 0 3 8];
normal = cross(Nodos(1,1:3)-Nodos(2,1:3), Nodos(1,1:3)-Nodos(3,1:3));
syms xs ys zs;
Pla = [xs, ys, zs];
planefunction1 = dot(normal, Pla - Nodos(1,1:3));
[Coe1, Var1] = coeffs(planefunction1)
%modification: use of diff with respect to xs, ys, zs
expected_ans = [diff(planefunction1, xs), diff(planefunction1, ys),diff(planefunction1, zs)]
coeffients = Pla
You can refer to diff MathWorks documentation page for more info on differentiate symbolic expression or function. You can also refer to coeffs MathWorks Documentation page for more info on coefficients of polynomial.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by