Question: How to substitute algebraic variables and functions into matrix equations?

I have a set of 15 equations in state space form, and I'm just trying to program a way to substitute all variables representing the time derivates as for example x__s_dot (t) as diff(x__s (t), t)  and diff( x__s_dot (t),t) as diff(x__s (t), t,t) so I can manipulate my equations easier.

The last half of the list xx has the variables that I want to substitute, the x,y and u (with respective diff(x__s (t), t) ) variables are always constant, but in the case of zeta, eta and u I might have indexes from 1 to n , in this case just 1 and 2.

I tried a bunch of methods including creating vectors with the seq, op commands and substituting them into my original equations with subs, algsubs but none of the things I programmed worked the way I wanted, I ended up with a very inefficient way , doing it manually, but the point is that I wanted to automate this bit. I've been doing maple for about 2 weeks and I still struggle a lot with it, I would greatly appreciate any guidence/advice.


My original equations are actually much bigger and my original code too, I tried to shorten it a bit just for making my problem simpler to understand but the equations still look really big here, If there is another way to format this question please do advice so.

EDIT : I think my last code was hard to understand because my equations were too big and it looked all messy and horrible, I edited to show just one vector of variables, I think that if it works here, it should work on the rest of my code:


 

NULL

interface(rtablesize=50):

xx := [x__s(t), y__s(t), u__s(t), x__r(t), y__r(t), u__r(t), x__c(t), y__c(t), u__c(t), zeta__1(t), eta__1(t), u__1(t), zeta__2(t), eta__2(t), u__2(t), x__s_dot(t), y__s_dot(t), u__s_dot(t), x__r_dot(t), y__r_dot(t), u__r_dot(t), x__c_dot(t), y__c_dot(t), u__c_dot(t), zeta__1_dot(t), eta__1_dot(t), u__1_dot(t), zeta__2_dot(t), eta__2_dot(t), u__2_dot(t)]:

nq := 15;            
xxUNDOT := [ seq ( xx[i], i = 1..nq),
             seq ( diff(xx[i],t), i = 1..nq)];
 

15

 

[x__s(t), y__s(t), u__s(t), x__r(t), y__r(t), u__r(t), x__c(t), y__c(t), u__c(t), zeta__1(t), eta__1(t), u__1(t), zeta__2(t), eta__2(t), u__2(t), diff(x__s(t), t), diff(y__s(t), t), diff(u__s(t), t), diff(x__r(t), t), diff(y__r(t), t), diff(u__r(t), t), diff(x__c(t), t), diff(y__c(t), t), diff(u__c(t), t), diff(zeta__1(t), t), diff(eta__1(t), t), diff(u__1(t), t), diff(zeta__2(t), t), diff(eta__2(t), t), diff(u__2(t), t)]

(1)

DOTL := [ seq ( xx[i], i = 1..nops(xx)) ]:
DOTR := [ seq ( xxUNDOT[i], i = 1..nops(xx))]:
Vector[column](DOTL),Vector[column](DOTR);

for i from nq+1 to nops(xx) do
newxx    := subs[inplace][eval](
  op(i,DOTL) = op(i,DOTR) ,xx):
end do:

Vector(30, {(1) = x__s(t), (2) = y__s(t), (3) = u__s(t), (4) = x__r(t), (5) = y__r(t), (6) = u__r(t), (7) = x__c(t), (8) = y__c(t), (9) = u__c(t), (10) = `ζ__1`(t), (11) = `η__1`(t), (12) = u__1(t), (13) = `ζ__2`(t), (14) = `η__2`(t), (15) = u__2(t), (16) = x__s_dot(t), (17) = y__s_dot(t), (18) = u__s_dot(t), (19) = x__r_dot(t), (20) = y__r_dot(t), (21) = u__r_dot(t), (22) = x__c_dot(t), (23) = y__c_dot(t), (24) = u__c_dot(t), (25) = `ζ__1_dot`(t), (26) = `η__1_dot`(t), (27) = u__1_dot(t), (28) = `ζ__2_dot`(t), (29) = `η__2_dot`(t), (30) = u__2_dot(t)}), Vector(30, {(1) = x__s(t), (2) = y__s(t), (3) = u__s(t), (4) = x__r(t), (5) = y__r(t), (6) = u__r(t), (7) = x__c(t), (8) = y__c(t), (9) = u__c(t), (10) = `ζ__1`(t), (11) = `η__1`(t), (12) = u__1(t), (13) = `ζ__2`(t), (14) = `η__2`(t), (15) = u__2(t), (16) = diff(x__s(t), t), (17) = diff(y__s(t), t), (18) = diff(u__s(t), t), (19) = diff(x__r(t), t), (20) = diff(y__r(t), t), (21) = diff(u__r(t), t), (22) = diff(x__c(t), t), (23) = diff(y__c(t), t), (24) = diff(u__c(t), t), (25) = diff(`ζ__1`(t), t), (26) = diff(`η__1`(t), t), (27) = diff(u__1(t), t), (28) = diff(`ζ__2`(t), t), (29) = diff(`η__2`(t), t), (30) = diff(u__2(t), t)})

(2)

Vector[column](newxx);

Vector(30, {(1) = x__s(t), (2) = y__s(t), (3) = u__s(t), (4) = x__r(t), (5) = y__r(t), (6) = u__r(t), (7) = x__c(t), (8) = y__c(t), (9) = u__c(t), (10) = `ζ__1`(t), (11) = `η__1`(t), (12) = u__1(t), (13) = `ζ__2`(t), (14) = `η__2`(t), (15) = u__2(t), (16) = x__s_dot(t), (17) = y__s_dot(t), (18) = u__s_dot(t), (19) = x__r_dot(t), (20) = y__r_dot(t), (21) = u__r_dot(t), (22) = x__c_dot(t), (23) = y__c_dot(t), (24) = u__c_dot(t), (25) = `ζ__1_dot`(t), (26) = `η__1_dot`(t), (27) = u__1_dot(t), (28) = `ζ__2_dot`(t), (29) = `η__2_dot`(t), (30) = diff(u__2(t), t)})

(3)

``


 

Download subs.mw

I tried to make a for loop that substitutes each variable one by one, but it only seems to work for the last term, I don't know why, please help or suggest another method? I also have diff(x__s,t,t) terms in my equations, not just diff(x__s,t), but I guess only by specifying the first derivate it should work?

 

Thanks.

 

Please Wait...