How can I rearrange an equation to multiple varriables?

2 ビュー (過去 30 日間)
Stan Smit
Stan Smit 2021 年 11 月 17 日
編集済み: Brahmadev 2024 年 2 月 16 日
Hi,
I have an equation (full of unkowns) whom I want to rearrange into the form:
e*(....) + f*(....)+g*(....) = (....)
I want to rewrite it to this form so I can implement it in an adaptive Excel document, where it will be used in a Matrix (where the other variables (except, e, f, g) will me known.
Is there a way to do this with Matlab?
The complete formula is:
(a*(YBL*e - YBR*e - YAL*f + YBR*f + YAL*g - YBL*g))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g) + (c*(XA - XB)*(YBL - YBR))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g) + (b*(XA - XB)*(f - g))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g)=1

回答 (1 件)

Brahmadev
Brahmadev 2024 年 2 月 16 日
編集済み: Brahmadev 2024 年 2 月 16 日
For manipulating equations that you have mentioned above, the Symbolic Math Toolbox can be very useful. You can use the 'diff' function to find the partial derivative with respect to 'e', 'f' and 'g' and find the coefficients after simplifying the code using the 'simplify' function.
% Defining variables as symbolic
syms a b c d e f g YAL YBL XA XB YBR
eqn = (a*(YBL*e - YBR*e - YAL*f + YBR*f + YAL*g - YBL*g))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g) + (c*(XA - XB)*(YBL - YBR))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g) + (b*(XA - XB)*(f - g))/(XB*YBL*e - XB*YBR*e - XB*YAL*f + XA*YBR*f - XA*YBL*g + XB*YAL*g) == 1;
% Getting the numerator and denominator for RHS and LHS
[LN, LD] = numden(lhs(eqn));
[RN, RD] = numden(rhs(eqn));
% Simplifying the equation and creating a new equation with denominator as
% 1
neweqn1 = simplify(LN * RD) - simplify(RN * LD) == 0;
% Finding the co-efficients of e, f and g
v_e = diff(neweqn1, e);
v_f = diff(neweqn1, f);
v_g = diff(neweqn1, g);
% Finding the constant expression to create final form of the equation
constant_expr = simplify(lhs(neweqn1) - lhs(v_e*e+v_f*f+v_g*g));
% Equation with rearranged coefficients
finaleqn = lhs(v_e*e+v_f*f+v_g*g) == constant_expr
finaleqn = 
Also, you can refer to the following documentation for more information:
  1. 'simplify': https://www.mathworks.com/help/symbolic/simplify.html
  2. 'numden': https://www.mathworks.com/help/symbolic/sym.numden.html
  3. 'diff': https://www.mathworks.com/help/symbolic/diff.html
Hope this helps in resolving your query!

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by