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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by