How do I get the "Null" coefficients of an equation?
6 次查看(过去 30 天)
显示 更早的评论
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
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!