Force symbolic simplification to eliminate variable

조회 수: 2 (최근 30일)
ludolfusexe
ludolfusexe 2024년 5월 23일
댓글: ludolfusexe 2024년 5월 26일
When breaking down a (long and complex) formula into the form , I use the approach of the lincoeffs script.
The problem is, that I still have u in b, because simplification isn't detecting that the terms cancel out.
Is there a trick to force the elimination of u-terms?
The symbolic expression is attached if you want to try it, the code is as follows:
% NOT WORKING - extract coefficients of ddddh_fun
syms u
% ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,'Steps',50);
---
% WORKING - extract coefficients of ddddh_fun
syms u
ddddh_fun = expand(ddddh_fun);
ddddh_fun_formula = formula(ddddh_fun) == 0;
[ddddh_fun_A,ddddh_fun_b] = lincoeffs(ddddh_fun_formula,u)
ddddh_fun_b = simplify(ddddh_fun_b,'Steps',50);
The problem with this is, that the very expanded expression from the working version isn't very readable when I do export is as Latex, which is necessary for me.
To read the symbolic function and the matlabFunction derived from this is also very hard this way.

채택된 답변

Paul
Paul 2024년 5월 24일
Hi ludolfusexe,
load ddddh_fun
symvar(ddddh_fun)
ans = 
syms u
% A*u = b
[A,b] = equationsToMatrix(ddddh_fun == 0,u)
A = 
b = 
Verify that A and b do not depend on u
symvar(A)
ans = 
symvar(b)
ans = 
Reverse sign of b for desired form: A*u + b = 0
b = -b;
Verify
simplify(ddddh_fun - (A*u + b))
ans(t) = 
0
  댓글 수: 1
ludolfusexe
ludolfusexe 2024년 5월 26일
Thank you for your reply, the solution is exactly what I was looking for.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by