> restart;

> with(CodeGeneration):

> with(linalg);

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...

-------------------------------------------------------------------------------------------------------------

                                         Exerc�cio de Otimiza��o Din�mica

Giovani Tonel ([email protected]) - Outubro de 2006

--------------------------------------------------------------------------------------------------------------

Equa��es do Balan�o de Massa e Energia

> eqf1:=Diff(h,t)=(Fe/Area-Fs);
eqf2:=Diff(Ca,t)=(1/tau)*(Cae-Ca)-k*Ca;

eqf3:=Diff(T,t)=(1/tau)*(Te-T)+(-Hr)*k*Ca*(1/(ro*Cp))-U*At*(T-Tw)*(1/(ro*Area*h*Cp));

eqf1 := Diff(h, t) = Fe/Area-Fs

eqf2 := Diff(Ca, t) = (Cae-Ca)/tau-k*Ca

eqf3 := Diff(T, t) = (Te-T)/tau-Hr*k*Ca/(ro*Cp)-U*At*(T-Tw)/(ro*Area*h*Cp)

> tau:=Area*h/Fe;
k:=ko*exp(-Ea/(R*T));

tau := Area*h/Fe

k := ko*exp(-Ea/(R*T))

Equa��es do Controlador

> Fs:=(Cv/Area)*(1-u1)*(h)^0.5;
Tw:=u2*(Tmax-Tmin)+Tmin;


Fs := Cv*(1-u1)*h^.5/Area

Tw := u2*(Tmax-Tmin)+Tmin

Valores das variav�is do estado est�cion�rio:

> estac:={h=hss,T=Tss, Ca=Cass, Tw=Twss, u1=u1ss, u2=u2ss};

estac := {h = hss, T = Tss, Ca = Cass, u1 = u1ss, u2 = u2ss, u2*(Tmax-Tmin)+Tmin = Twss}

> u2ss:=Twss;

u2ss := Twss

> Fss=subs(estac,eval(Fs));

Fss = Cv*(1-u1ss)*hss^.5/Area

> eqf1:=Diff(h,t)=(Fe/Area-Fs);
eqf2:=Diff(Ca,t)=(1/tau)*(Cae-Ca)-k*Ca;

eqf3:=Diff(T,t)=(1/tau)*(Te-T)+(-Hr)*k*Ca*(1/(ro*Cp))-U*At*(T-Tw)*(1/(ro*Area*h*Cp));

eqf1 := Diff(h, t) = Fe/Area-Cv*(1-u1)*h^.5/Area

eqf2 := Diff(Ca, t) = Fe*(Cae-Ca)/(Area*h)-ko*exp(-Ea/(R*T))*Ca

eqf3 := Diff(T, t) = Fe*(Te-T)/(Area*h)-Hr*ko*exp(-Ea/(R*T))*Ca/(ro*Cp)-U*At*(T-u2*(Tmax-Tmin)-Tmin)/(ro*Area*h*Cp)

> eq5:=Diff(Y,T)=F(Y,U);
Y=matrix([[H],[CA],[T]]);

U=matrix([[u1],[u2]]);

eq5 := Diff(Y, T) = F(Y, U)

Y = matrix([[H], [CA], [T]])

U = matrix([[u1], [u2]])

> f:=vector([rhs(eqf1),rhs(eqf2),rhs(eqf3)]);

f := vector([Fe/Area-Cv*(1-u1)*h^.5/Area, Fe*(Cae-Ca)/(Area*h)-ko*exp(-Ea/(R*T))*Ca, Fe*(Te-T)/(Area*h)-Hr*ko*exp(-Ea/(R*T))*Ca/(ro*Cp)-U*At*(T-u2*(Tmax-Tmin)-Tmin)/(ro*Area*h*Cp)])

Vari�veis de Estado (x):

> y:=vector([h,Ca,T]);

y := vector([h, Ca, T])

Variaveis Manipuladas u:

> u:=vector([u1,u2]);

u := vector([u1, u2])

Aplicando Jacobiano no vetor f em rela��o a y,u, temos:

> jacobian([f1(y,u),f2(y,u),f3(y,u)],[y,u]);

matrix([[diff(f1(y, u), y), diff(f1(y, u), u)], [diff(f2(y, u), y), diff(f2(y, u), u)], [diff(f3(y, u), y), diff(f3(y, u), u)]])

Aplicando Jacobiano no vetor f em rela��o as variaveis de estado, temos:

> jacfy:=jacobian(f,y);

jacfy := matrix([[-.5*Cv*(1-u1)/(Area*h^.5), 0, 0], [-Fe*(Cae-Ca)/(Area*h^2), -Fe/(Area*h)-ko*exp(-Ea/(R*T)), -ko*Ea*exp(-Ea/(R*T))*Ca/(R*T^2)], [-Fe*(Te-T)/(Area*h^2)+U*At*(T-u2*(Tmax-Tmin)-Tmin)/(ro...

Substituindo os valores das vari�veis no estado estacion�rio no Jacobiano de f, temos:

> A:=subs(estac,evalm(jacfy));

A := matrix([[-.5*Cv*(1-u1ss)/(Area*hss^.5), 0, 0], [-Fe*(Cae-Cass)/(Area*hss^2), -Fe/(Area*hss)-ko*exp(-Ea/(R*Tss)), -ko*Ea*exp(-Ea/(R*Tss))*Cass/(R*Tss^2)], [-Fe*(Te-Tss)/(Area*hss^2)+U*At*(Tss-Twss...

Aplicando Jacobiano no vetor f em rela��o as variaveis manipuladas, temos:

> jacfu:=jacobian(f,u);

jacfu := matrix([[Cv*h^.5/Area, 0], [0, 0], [0, -U*At*(-Tmax+Tmin)/(ro*Area*h*Cp)]])

Substituindo os valores das vari�veis no estado estacion�rio no Jacobiano de f em rela��o as manipuladas, temos:

> B:=subs(estac,evalm(jacfu));

B := matrix([[Cv*hss^.5/Area, 0], [0, 0], [0, -U*At*(-Tmax+Tmin)/(ro*Area*hss*Cp)]])

Exportando para o MatLab

> Fortran(A,resultname="A");

     A(1,1) = -0.5D0 * dble(Cv) / dble(Area) * dble(1 - u1ss) * dble(hs
    #s ** (-0.5D0))

     A(2,1) = -1 / Area / hss ** 2 * Fe * (Cae - Cass)

     A(2,2) = -dble(1 / Area / hss * Fe) - ko * exp(-Ea / R / Tss)

     A(2,3) = -ko * Ea / R / Tss ** 2 * exp(-Ea / R / Tss) * dble(Cass)

     A(3,1) = -0.1D1 / dble(Area) / dble(hss ** 2) * dble(Fe) * (Te - T

    #ss) + U * At * (Tss - Twss * (Tmax - Tmin) - Tmin) / ro / dble(Are

    #a) / dble(hss ** 2) / Cp

     A(3,2) = -Hr * ko * exp(-Ea / R / Tss) / ro / Cp

     A(3,3) = -dble(1 / Area / hss * Fe) - Hr * ko * Ea / R / Tss ** 2

    #* exp(-Ea / R / Tss) * dble(Cass) / ro / Cp - U * At / ro / dble(A

    #rea) / dble(hss) / Cp

> Fortran(B,resultname="B");

     B(1,1) = Cv / Area * hss ** 0.5D0
     B(3,2) = -U * At * (-Tmax + Tmin) / ro / Area / hss / Cp

> u:=-K*x;

u := -K*x

> Diff(xot,t)=A*x+B*u;
Diff(xot,t)=Ak*xot;

Ak=(A-BK);

Diff(xot, t) = A*x-B*K*x

Diff(xot, t) = Ak*xot

Ak = A-BK

>

> x:=matrix([[h],[Ca],[T]]);

x := matrix([[h], [Ca], [T]])

> u:=matrix([[u1],[u2]]);

u := matrix([[u1], [u2]])

Substituindo o estacion�rio:

> A =matrix([[-0.0875,0, 0],[-20.8793,-30.3926,-0.6203],[ 36.5291, 54.3873, 0.8451]]);
 

A = matrix([[-0.875e-1, 0, 0], [-20.8793, -30.3926, -.6203], [36.5291, 54.3873, .8451]])

> B=matrix([[-0.4375,0],[0,0],[ 0, 45.3178]]);

B = matrix([[-.4375, 0], [0, 0], [0, 45.3178]])

> C=matrix([[1,0,0],[0,0,1]]);

C = matrix([[1, 0, 0], [0, 0, 1]])

> D=matrix([[0,0],[0,0]]);

D = matrix([[0, 0], [0, 0]])

> Q=matrix([[1,0,0],[0,0,1]]);

Q = matrix([[1, 0, 0], [0, 0, 1]])

> R=matrix([[1,0],[0,1]]);

R = matrix([[1, 0], [0, 1]])

Dados do Matlab

> Ak:=matrix([[-0.5382,-0.0003,-0.0020],[-20.8793,-30.3926,-0.6203],[14.7067, 21.9636,-44.8792]]);

Ak := matrix([[-.5382, -0.3e-3, -0.20e-2], [-20.8793, -30.3926, -.6203], [14.7067, 21.9636, -44.8792]])

> K:=matrix([[-1.0302,-0.0007,-0.0046],[0.4815,0.7155,1.0090]]);

K := matrix([[-1.0302, -0.7e-3, -0.46e-2], [.4815, .7155, 1.0090]])

> P:=matrix([[2.3548, 0.0017,0.0106],[0.0017, 0.0363,0.0158],[0.0106,0.0158,0.0223]]);

P := matrix([[2.3548, 0.17e-2, 0.106e-1], [0.17e-2, 0.363e-1, 0.158e-1], [0.106e-1, 0.158e-1, 0.223e-1]])

> E:=matrix([[-43.8656],[-31.4064],[-0.5380]]);
  

E := matrix([[-43.8656], [-31.4064], [-.5380]])

>

>

1