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

7 ビュー (過去 30 日間)
Pedro Guevara
Pedro Guevara 2021 年 1 月 11 日
回答済み: Sai Sumanth Korthiwada 2022 年 2 月 24 日
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 件のコメント
David Goodmanson
David Goodmanson 2021 年 1 月 12 日
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 ?

サインインしてコメントする。

回答 (1 件)

Sai Sumanth Korthiwada
Sai Sumanth Korthiwada 2022 年 2 月 24 日
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.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by