- 'simplify': https://www.mathworks.com/help/symbolic/simplify.html
- 'numden': https://www.mathworks.com/help/symbolic/sym.numden.html
- 'diff': https://www.mathworks.com/help/symbolic/diff.html
How can I rearrange an equation to multiple varriables?
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
Also, you can refer to the following documentation for more information:
Hope this helps in resolving your query!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!