Question: how do i write this procedure in maplet.

 

 

 

 

 

 

 

 

 

proc5.mw

 

 

 

restart

Digits := 5

5

(1)

with(GraphTheory):

with(LinearAlgebra):

lc := proc (Ndx, Ndy, Tb, Td, Th, Tg, C) local imax, jmax, Ndeq, G, i, T, j, k, Eq, var, sys, A, B, Ainvers, TT, L1, L2; imax := Ndx+1; jmax := Ndy+1; Ndeq := (imax-2)*(jmax-2); G := GridGraph(imax, jmax); DrawGraph(G); for i to imax do T[i, 1] := Tb end do; for i to imax do T[i, jmax] := Th end do; for j to jmax do T[1, j] := Tg end do; for j to jmax do T[imax, j] := Td end do; k := 1; for j from 2 to jmax-1 do for i from 2 to imax-1 do Eq[k] := -4*T[i, j]+T[i-1, j]+T[1+i, j]+T[i, j-1]+T[i, j+1] = 0; var[k] := T[i, j]; k := k+1 end do end do; for k to Ndeq do Eq[k]; var[k] end do; sys := [seq(Eq[k], k = 1 .. Ndeq)]; L1 := convert(sys, Vector); var := [seq(var[k], k = 1 .. Ndeq)]; L2 := convert(var, Vector); A, B := GenerateMatrix(sys, var); Ainvers := MatrixInverse(A); TT := MatrixVectorMultiply(Ainvers, B); evalf(TT); if C = 1 then DrawGraph(G) elif C = 2 then L1 end if end proc;

proc (Ndx, Ndy, Tb, Td, Th, Tg, C) local imax, jmax, Ndeq, G, i, T, j, k, Eq, var, sys, A, B, Ainvers, TT, L1, L2; imax := Ndx+1; jmax := Ndy+1; Ndeq := (imax-2)*(jmax-2); G := GraphTheory:-SpecialGraphs:-GridGraph(imax, jmax); GraphTheory:-DrawGraph(G); for i to imax do T[i, 1] := Tb end do; for i to imax do T[i, jmax] := Th end do; for j to jmax do T[1, j] := Tg end do; for j to jmax do T[imax, j] := Td end do; k := 1; for j from 2 to jmax-1 do for i from 2 to imax-1 do Eq[k] := -4*T[i, j]+T[i-1, j]+T[1+i, j]+T[i, j-1]+T[i, j+1] = 0; var[k] := T[i, j]; k := k+1 end do end do; for k to Ndeq do Eq[k]; var[k] end do; sys := [seq(Eq[k], k = 1 .. Ndeq)]; L1 := convert(sys, Vector); var := [seq(var[k], k = 1 .. Ndeq)]; L2 := convert(var, Vector); A, B := LinearAlgebra:-GenerateMatrix(sys, var); Ainvers := LinearAlgebra:-MatrixInverse(A); TT := LinearAlgebra:-MatrixVectorMultiply(Ainvers, B); evalf(TT); if C = 1 then GraphTheory:-DrawGraph(G) elif C = 2 then L1 end if end proc

(2)

lc(6, 3, 40, 60, 70, 90, 2)

Vector[column]([[-4*T[2, 2]+130+T[3, 2]+T[2, 3] = 0], [-4*T[3, 2]+T[2, 2]+T[4, 2]+40+T[3, 3] = 0], [-4*T[4, 2]+T[3, 2]+T[5, 2]+40+T[4, 3] = 0], [-4*T[5, 2]+T[4, 2]+T[6, 2]+40+T[5, 3] = 0], [-4*T[6, 2]+T[5, 2]+100+T[6, 3] = 0], [-4*T[2, 3]+160+T[3, 3]+T[2, 2] = 0], [-4*T[3, 3]+T[2, 3]+T[4, 3]+T[3, 2]+70 = 0], [-4*T[4, 3]+T[3, 3]+T[5, 3]+T[4, 2]+70 = 0], [-4*T[5, 3]+T[4, 3]+T[6, 3]+T[5, 2]+70 = 0], [-4*T[6, 3]+T[5, 3]+130+T[6, 2] = 0]])

(3)

``

 

Download proc5.mw

Please Wait...