Question: Equation substitution problem

I have a set of test equations. I am substituting the coefficients of the variables A1 ..A4 and the constants in the equations. Most of this I have made work fine. There are 2 coefficients I cand make be substituted. In eq1 k*d the coefficient of A3 and eq5 3.1d2 also the coeff of A3 .Have tried subs and algsubs but can't make it work. The reason I want to do this is in reality I have 15 equations with really long polynomial coeffs, they are too difficult to read and see what happens when I form a matrix. Would appreciate and insght on this issue.
 

restart

with(LinearAlgebra):

eq[1] := (5.0+d^3)*A[1]+(7.0-2*d)*A[4]-k*d*A[3]+4.8+d:

NULL

``

for j to 5 do for i to 4 do RevCoeff[10*j+i] := coeff(eq[j], A[i]) end do end do

``

c[1] := 0; c[2] := 0; c[3] := 0; c[4] := 0; c[5] := 0; for j to 5 do for i to 4 do c[j] := c[j]+RevCoeff[10*j+i]*A[i] end do end do; for i to 5 do RevConst[i] := eq[i]-c[i]; eq[i] := c[i]+Const[i] end do

(8.2*d+1.0)*A[1]+3.1*d^2*A[3]+Const[5]

(1)

``

(2)

for j to 5 do for i to 4 do eq[j] := subs(coeff(eq[j], A[i]) = Coeff[10*j+i], eq[j]) end do end do;

for i to 5 do print(eq[i]) end do

Coeff[51]*A[1]+3.1*d^2*A[3]+Const[5]

(3)

``

sys := [eq[1], eq[2], eq[3], eq[4], eq[5]]:

variables := [A[1], A[2], A[3], A[4]]:

A, b := GenerateMatrix(sys, variables):

```<|>`(A, -1*b):````````````

``

``


Download in_out_subs.mw

Please Wait...