0
|
1084 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# Calculate using different matrices A and B

Posted 6 months ago
 Obtain two sets of state matrices A1, B1, and A2, B2 from the circuit drawn by System Modeler. The following code needs to use two sets of matrices for calculation. How can I use two sets of matrices without duplicating the code below? {r = 22, l = 2 10^-1, c = 1 10^-4, vi = 24, initvalueil = 0, initvaluevc = 0, tstart = 0, tend = 0.08, stepsize = 0.00006}; model = SystemModelLinearize["Model2", Method -> {"SymbolicDerivative", "SymbolicParameters" -> {"r", "l", "c", "k1", "k2"}}]; kVals = Thread[{QuantityVariable["k1", IndependentPhysicalQuantity[""]], QuantityVariable["k2", IndependentPhysicalQuantity[""]]} -> #] & /@ {{False, True}, {True, False}}; spacemodel = {#, model /. #} & /@ kVals; rule = {QuantityVariable["r", IndependentPhysicalQuantity[""]] -> r, QuantityVariable["l", IndependentPhysicalQuantity[""]] -> l, QuantityVariable["c", IndependentPhysicalQuantity[""]] -> c}; spacemodel1 = spacemodel[[1, 2]] /. rule; spacemodel2 = spacemodel[[2, 2]] /. rule; (*Two sets of state matrices A1,B1 and A2,B2*) A1 = spacemodel1[[1, 1]]; B1 = Flatten[spacemodel1[[1, 2]]]; A2 = spacemodel2[[1, 1]]; B2 = Flatten[spacemodel2[[1, 2]]]; X = Transpose[{{vc, il}}]; X0 = Transpose[{{0, 0}}]; (*Can I include matrices A1,B1,A2,and B2 in A and B below,and only \ calculate once to obtain corresponding results and curves?*) Asi = s*DiagonalMatrix[{1, 1}] - A;(*Matrix A*) AA = Inverse[Asi]; eAt = InverseLaplaceTransform[AA, s, t]; eAt\[Tau] = ReplaceAll[eAt, t -> t - \[Tau]]; X = eAt . X0 + Integrate[eAt\[Tau] . B*vi, {\[Tau], 0, t}](*Matrix B*) vc = X[[1, 1]]; il = X[[2, 1]]; p1 = Plot[{il}, {t, 0, .08}, AxesLabel -> {"s", "il[t]/A"}, PlotLegends -> {"LaplaceTransform"}, PlotStyle -> {Green}, PlotRange -> All] p2 = Plot[{vc}, {t, 0, .08}, AxesLabel -> {"s", "vc[t]/A"}, PlotLegends -> {"LaplaceTransform"}, PlotStyle -> {Yellow}, PlotRange -> All]  For detailed code and problem description, see Appendix Notebook and Circuit. Attachments:
2 Replies
Sort By:
Posted 6 months ago
Posted 6 months ago
 Hello, sir! Thank you very much for your answer, which fits my needs very well.