Simplify symbolic functions: remove terms
45 ビュー (過去 30 日間)
古いコメントを表示
Hi I want to simplify a symbolic function in this way:
this is my function:
a*b+dx*dy+dx^2*dy+a*dx+a+dy*dz+dt*da
I want that Matlab:
- Remove the terms in which there is a product between dx*dy, dy*dx, dt*da, dx^2*dy etc.
- Make two function: In the first there are all terms that are multiplied by dx, dy, dt and in the other, the other terms.
Thanks!
回答 (2 件)
Hildo
2016 年 11 月 29 日
Do you want to remove a specific variable
You can use
new_equation = subs(equation,var,0);
new_equation2 = simplify(equation); % Maybe is not necessary simplify in this case
Of all the cross multiplication between variables?
0 件のコメント
Walter Roberson
2016 年 11 月 29 日
Note: for this purpose I exclude all squared terms such as dx^2, guessing that your rule was that multiplying two or more derivatives together was going to give a result too small to matter.
syms a b dx dy dz dt da
r = a*b+dx*dy+dx^2*dy+a*dx+a+dy*dz+dt*da;
[A,B] = coeffs(r,[dx,dy,dz,da,dt], 'all');
[tf, idx] = ismember([dx,dy,dz,da,dt],B);
just_constants = cellfun(@(C) isempty(symvar(C)), num2cell(B));
first_term = sum(A(idx(tf)) .* B(idx(tf)));
second_term = sum(A(just_constants) .* B(just_constants));
4 件のコメント
Walter Roberson
2016 年 11 月 29 日
I did test the code with the expression you gave.
My expression originally involved some positional computations, but in mentally reviewing, I think that you are correct that the 'all' is not actually necessary, but it should not hurt.
参考
カテゴリ
Help Center および File Exchange で Assumptions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!