Question: About substitutions

Dear All

I want to use subs command to replace products in expression with entries from matrix. When I use "subs" command it returns same result as original without any substitution. But when I use "algsubs", it works fine, but is complicated to apply if there are large number of substitutions.

Please see followings:

 

M := Matrix([[U[1], U[2], -epsilon*U[1]+U[3], U[4], U[5], U[6]], [U[1], U[2], -epsilon*U[2]+U[3], epsilon*U[1]+U[4], epsilon*U[2]+U[5], U[6]], [e^epsilon*U[1], e^epsilon*U[2], U[3], U[4], U[5], U[6]], [U[1], -epsilon*U[1]+U[2], U[3], U[4], -epsilon*U[4]+U[5], U[6]-epsilon*(U[3]+2*U[5])+epsilon^2*U[4], U[1], e^(-epsilon)*U[2], U[3], e^epsilon*U[4], U[5], e^(-epsilon)*U[6]], [U[1], e^(-epsilon)*U[2], U[3], e^epsilon*U[4], U[5], e^(-epsilon)*U[6]], [epsilon*U[2]+U[1], U[2], U[3], U[4]+epsilon*(U[3]+2*U[5])+epsilon^2*U[6], epsilon*U[6]+U[5], U[6]]])

M := Vector(4, {(1) = ` 6 x 12 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(1)

M[5, 1]; 1; M[5, 3]

U[1]

 

U[3]

(2)

expand((w*T[5]+z*T[4]+T[6])*(U[1]*a[1]+U[2]*a[2]+U[3]*a[3]+U[4]*a[4]+U[5]*a[5]+U[6]*a[6]))

w*T[5]*U[1]*a[1]+w*T[5]*U[2]*a[2]+w*T[5]*U[3]*a[3]+w*T[5]*U[4]*a[4]+w*T[5]*U[5]*a[5]+w*T[5]*U[6]*a[6]+z*T[4]*U[1]*a[1]+z*T[4]*U[2]*a[2]+z*T[4]*U[3]*a[3]+z*T[4]*U[4]*a[4]+z*T[4]*U[5]*a[5]+z*T[4]*U[6]*a[6]+T[6]*U[1]*a[1]+T[6]*U[2]*a[2]+T[6]*U[3]*a[3]+T[6]*U[4]*a[4]+T[6]*U[5]*a[5]+T[6]*U[6]*a[6]

(3)

subs(T[5]*U[1] = M[5, 1], T[5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3]+z*T[4]*U[4]*a[4]+z*T[4]*U[5]*a[5]+z*T[4]*U[6]*a[6]+T[6]*U[2]*a[2]+T[6]*U[3]*a[3]+T[6]*U[4]*a[4]+T[6]*U[5]*a[5]+T[6]*U[6]*a[6]+(w*U[2]*a[2]+w*U[3]*a[3]+w*U[4]*a[4]+w*U[5]*a[5]+w*U[6]*a[6])*T[5]+(z*T[4]*a[1]+w*a[1]+T[6]*a[1])*U[1]

(5)

It worked !!!! But If I try "algsubs" like :

algsubs(T[5]*U[1] = M[5, 1], T[5]*U[2] = M[5, 2], T[5]*U[3] = M[5, 3], w*T[5]*U[1]*a[1]+w*T[5]*U[2]*a[2]+w*T[5]*U[3]*a[3]+w*T[5]*U[4]*a[4]+w*T[5]*U[5]*a[5]+w*T[5]*U[6]*a[6]+z*T[4]*U[1]*a[1]+z*T[4]*U[2]*a[2]+z*T[4]*U[3]*a[3]+z*T[4]*U[4]*a[4]+z*T[4]*U[5]*a[5]+z*T[4]*U[6]*a[6]+T[6]*U[1]*a[1]+T[6]*U[2]*a[2]+T[6]*U[3]*a[3]+T[6]*U[4]*a[4]+T[6]*U[5]*a[5]+T[6]*U[6]*a[6])

Error, invalid input: algsubs expects its 3rd argument, x, to be of type {name, function, list({name, function}), set({name, function})}, but received T[5]*U[3] = U[3]

 

See it is giving error !!! but still I can use "algsubs" as follow:

 

expand(algsubs(T[6]*U[6] = M[6, 6], expand(algsubs(T[6]*U[5] = M[6, 5], expand(algsubs(T[6]*U[4] = M[6, 4], expand(algsubs(T[6]*U[3] = M[6, 3], expand(algsubs(T[6]*U[2] = M[6, 2], expand(algsubs(T[6]*U[1] = M[6, 1], expand(algsubs(T[5]*U[6] = M[5, 6], expand(algsubs(T[5]*U[5] = M[5, 5], expand(algsubs(T[5]*U[4] = M[5, 4], expand(algsubs(T[5]*U[3] = M[5, 3], expand(algsubs(T[5]*U[2] = M[5, 2], expand(algsubs(T[5]*U[1] = M[5, 1], expand(algsubs(T[4]*U[6] = M[4, 6], expand(algsubs(T[4]*U[5] = M[4, 5], expand(algsubs(T[4]*U[4] = M[4, 4], expand(algsubs(T[4]*U[3] = M[4, 3], expand(algsubs(T[4]*U[2] = M[4, 2], expand(algsubs(T[4]*U[1] = M[4, 1], expand(algsubs(T[3]*U[6] = M[3, 6], expand(algsubs(T[3]*U[5] = M[3, 5], expand(algsubs(T[3]*U[4] = M[3, 4], expand(algsubs(T[3]*U[3] = M[3, 3], expand(algsubs(T[3]*U[2] = M[3, 2], expand(algsubs(T[3]*U[1] = M[3, 1], expand(algsubs(T[2]*U[6] = M[2, 6], expand(algsubs(T[2]*U[5] = M[2, 5], expand(algsubs(T[2]*U[4] = M[2, 4], expand(algsubs(T[2]*U[3] = M[2, 3], expand(algsubs(T[2]*U[3] = M[2, 3], expand(algsubs(T[2]*U[2] = M[2, 2], expand(algsubs(T[2]*U[1] = M[2, 1], expand(algsubs(T[1]*U[6] = M[1, 6], expand(algsubs(T[1]*U[5] = M[1, 5], expand(algsubs(T[1]*U[4] = M[1, 4], expand(algsubs(T[1]*U[3] = M[1, 3], expand(algsubs(T[1]*U[2] = M[1, 2], expand(algsubs(T[1]*U[1] = M[1, 1], w*T[5]*U[1]*a[1]+w*T[5]*U[2]*a[2]+w*T[5]*U[3]*a[3]+w*T[5]*U[4]*a[4]+w*T[5]*U[5]*a[5]+w*T[5]*U[6]*a[6]+z*T[4]*U[1]*a[1]+z*T[4]*U[2]*a[2]+z*T[4]*U[3]*a[3]+z*T[4]*U[4]*a[4]+z*T[4]*U[5]*a[5]+z*T[4]*U[6]*a[6]+T[6]*U[1]*a[1]+T[6]*U[2]*a[2]+T[6]*U[3]*a[3]+T[6]*U[4]*a[4]+T[6]*U[5]*a[5]+T[6]*U[6]*a[6]))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

a[5]*epsilon*U[6]+a[1]*epsilon*U[2]+U[6]*a[6]+U[2]*a[2]+U[3]*a[3]+U[4]*a[4]+U[5]*a[5]+z*a[1]*U[1]+epsilon^2*U[6]*a[4]+epsilon*U[3]*a[4]+2*epsilon*U[5]*a[4]+U[6]*w*a[6]/e^epsilon+U[4]*e^epsilon*w*a[4]+w*a[1]*U[1]+U[2]*w*a[2]/e^epsilon+epsilon^2*z*U[4]*a[6]-epsilon*z*U[3]*a[6]-2*epsilon*z*U[5]*a[6]+w*U[3]*a[3]+w*U[5]*a[5]-z*a[5]*epsilon*U[4]-z*a[2]*epsilon*U[1]+z*U[2]*a[2]+z*U[3]*a[3]+z*U[4]*a[4]+z*U[5]*a[5]+z*U[6]*a[6]+a[1]*U[1]

(6)

But this procedure is complex, I want to use "subs" only. I know it complexity of terms in (3) might me creating problem.

collect(a[5]*epsilon*U[6]+a[1]*epsilon*U[2]+U[6]*a[6]+U[2]*a[2]+U[3]*a[3]+U[4]*a[4]+U[5]*a[5]+z*a[1]*U[1]+epsilon^2*U[6]*a[4]+epsilon*U[3]*a[4]+2*epsilon*U[5]*a[4]+U[6]*w*a[6]/e^epsilon+U[4]*e^epsilon*w*a[4]+w*a[1]*U[1]+U[2]*w*a[2]/e^epsilon+epsilon^2*z*U[4]*a[6]-epsilon*z*U[3]*a[6]-2*epsilon*z*U[5]*a[6]+w*U[3]*a[3]+w*U[5]*a[5]-z*a[5]*epsilon*U[4]-z*a[2]*epsilon*U[1]+z*U[2]*a[2]+z*U[3]*a[3]+z*U[4]*a[4]+z*U[5]*a[5]+z*U[6]*a[6]+a[1]*U[1], [U[1], U[2], U[3], U[4], U[5], U[6]])

(-epsilon*z*a[2]+w*a[1]+z*a[1]+a[1])*U[1]+(a[1]*epsilon+a[2]+w*a[2]/e^epsilon+z*a[2])*U[2]+(-epsilon*z*a[6]+epsilon*a[4]+w*a[3]+z*a[3]+a[3])*U[3]+(epsilon^2*z*a[6]+e^epsilon*w*a[4]-z*a[5]*epsilon+z*a[4]+a[4])*U[4]+(-2*epsilon*z*a[6]+2*epsilon*a[4]+w*a[5]+z*a[5]+a[5])*U[5]+(a[5]*epsilon+a[6]+epsilon^2*a[4]+w*a[6]/e^epsilon+z*a[6])*U[6]

(7)

``

 

Download Subs_not_giving_result.mwSubs_not_giving_result.mw

Regards

Please Wait...