Given a polynomial in n variables f=f(x1,x2,…,xn) (given by symbolic). I would like to implement a code that takes f and i(for any number from 1 through n-1) and gives the new function P=((1-x(i+1))*f(x1,…,xn)-(1-xi)*f(x1,…x(i+1), xi, …, xn))/(xi-x(i+1)).
I wrote the following brute force two pieces of code: The first one is to swap to variables, and the second for the isobaric difference
1s code
function [ P ] = swap( f, i )X=symvar(f);Y=X;Y(i)=X(i+1);Y(i+1)=X(i);P=subs(f,X,Y);end
2nd code
function [ P ] = isodiff( f,i )X=symvar(f);P=((1-X(i+1))*f-(1-X(i))*swap(f,i))./(X(i)-X(i+1));P=simplify(P);end
Is there a more efficient way to solve this problem?
Best Answer