Can not calculate coefficient Accurately

1 回表示 (過去 30 日間)
inzamam shoukat
inzamam shoukat 2024 年 3 月 27 日
回答済み: Star Strider 2024 年 3 月 27 日
My equation is
Disp =X1*(4*X2 - 4*X1 + 1)
I am using Fallowing Command
[EQ_01, T] =coeffs(Disp , [X1 X2])
N1 = EQ_01(1) by using this cammand i got fallowing answer
N1 = -4
My required answer is 1 - 4X1
N2 = EQ_01(2) by using this cammand i got fallowing answer
N2 =4
My required answer is
4X1

回答 (2 件)

Lokesh
Lokesh 2024 年 3 月 27 日
Hi inzamam,
As per my understanding, the values of coefficients returned from 'coeffs' is different from your expected values.
Given your equation 'Disp =X1*(4*X2 - 4*X1 + 1)' and the MATLAB command '[EQ_01, T] =coeffs(Disp , [X1 X2])' , 'coeffs' returns the coefficients of 'Disp' with respect to the symbolic variables 'X1' and 'X2'. When extracting coefficients of 'Disp' with 'X1' and 'X2' as variables, the equation simplifies to '-4X1^2 + 4X1X2 + X1'. This operation will return the coefficients of 'X1^2', 'X1X2' , and 'X1', which are -4, 4, and 1, respectively.
It is important to note that when obtaining coefficients with respect to 'X1', 'X1' itself cannot appear in the coefficients. This is because the operation is designed to isolate the factors multiplying 'X1' directly, not to include 'X1' as part of its own coefficient.
Refer to the following documentation to know more about 'coeffs':

Star Strider
Star Strider 2024 年 3 月 27 日
Only request the coefficients of ‘X2’ and then divide ‘EQ_01(2)’ by ‘X1’
syms X1 X2
Disp = X1*(4*X2 - 4*X1 + 1)
Disp = 
[EQ_01, T] =coeffs(Disp , X2)
EQ_01 = 
T = 
EQ_01(2) = EQ_01(2)/X1
EQ_01 = 
If you are required to get that result without the extra division by ‘X1’, be sure that you entered ‘Disp’ correctly.
.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by