| ★ wanayoo — archive 1999 http://www.maplesoft.com/apps/categories/engineering/model_simulation/html/matla1.html | Nouvelle recherche | Portail wanayoo |
Matlab Link Application
© 1998 Waterloo Maple Inc.
NOTE: This worksheet demonstrates the Matlab link in Maple through applications in the areas of Structural Analysis, Heat Transfer, and Data Analysis.
Introduction
This worksheet demonstrates the Matlab Link.
> restart;
> with(linalg): with(plots):
with(Matlab);
Warning, new definition for norm
Warning, new definition for trace
Warning, new definition for det
Warning, new definition for transpose
Structural Analysis: A First Approximation
Compute the lowest natural frequencies and modes of a highly idealized 22 story building by formulating the model equations with the following matrix assignments.
The mass matrix M is
> M:=diag(seq(m,i=1..22)):
The stiffness matrix K is
> K:=band([-k,2*k,-k],22):K[22,22]:=-k:
> K:=subs(k=1.25e8,evalm(K)):
> M:=subs(m=5000,evalm(M)):
Find the Eigenvalues and
Eigenvectors computed with Matlab using
> (P,W):=eig(K,M,eigenvectors=true):
The Eigenvalues are
> print(W):
[[99502.411598707,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,98019.383842331,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,95579.942139184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,92231.842914352,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,88040.658180896,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,83088.520670161,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,77472.555848527,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,71303.034123987,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,64701.283157111,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,57797.406382185,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,50727.859518493,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,43632.941754225,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,36654.261736137,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,29932.23882375,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,23603.693532886,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17799.560271511,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12642.707945713,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,532.57050205112,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2115.9723427147,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4708.7225072088,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8245.7655412057,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-33333.333333333]]
The Eigenvectors are
> print(P):
[[0.042193062899764, 0.08355509195746, 0.1232710276168, 0.16055743602872, 0.19467752002146, 0.22495518244022,-0.25078784995766, 0.27165778536289,-0.28714164088509,-0.2969180351779, 0.30077297517209, 0.29860299879654,-0.29041600294673,-0.27632987859997,-0.25656936627654, 0.23146206547081,-0.20143535513972, 0.044380888638375, 0.087666697302102, 0.12884196575323, -0.16701694523666,8.0117034782908e-011],[-0.083546334650971,-0.16049056130746, -0.22474745224847,-0.27122545668383,-0.29622643978564,-0.29773736816132, 0.27559132856375,-0.23148540286528, 0.16885402275396, 0.092607623299275, -0.0087568189153809, 0.076048907428032,-0.15503263851858,-0.22181288038426, -0.27089934489235, 0.29812721154497,-0.30100317568054, 0.087816339191005, 0.16791338232947, 0.23341668894585,-0.27894658760013,2.6705678260969e-010], [0.12323673891846, 0.2247112227023, 0.28648800715977, 0.29761659921309, 0.25606842957971, 0.16911237998719,-0.052060076655827,-0.07440412790513, 0.18784680885616, 0.26803406425979,-0.30051802581212,-0.27923468587167, 0.20765500230573, 0.09827836222527, -0.029460318904219, 0.15253102680026,-0.24835118658691, 0.12938105406959, 0.2339480644376, 0.29402763546658,-0.2988711035688,8.1007224058274e-010],[-0.16047429631,-0.27112921695739, -0.29757681934803,-0.231530441983,-0.093414024236789, 0.073910228929875,-0.21838239402752, 0.29488674989442,-0.27931758784012,-0.17620644423136, 0.017506215138027,-0.14716504779546, 0.26588501091675, 0.30070194846144, 0.23979360063576,-0.10166456613672,-0.070105936693699, 0.1681895876313, 0.28018164118647, 0.29925880019278,-0.22021877765467,2.4331840193328e-009], [0.19451784775956, 0.29606709489559, 0.25605336115406, 0.093501691015568,-0.11392719096797, -0.26693558549449, 0.29204097730606,-0.17687517192336,-0.023593730872217,-0.21307593414652, 0.30000834319928, 0.24175434862943,-0.065717731746555, 0.14309823325303, 0.2826469337536, -0.2834767761766, 0.14359246851468, 0.20341520866802, 0.30270095378786, 0.24812489900107, -0.068931555408095,7.3005411571932e-009],[-0.22468980621353,-0.29754916195761, -0.1692590760898, 0.073580492895168, 0.26676863740167, 0.27938991659956,-0.10254208833644, -0.14416763696765, 0.29319191257153, 0.24266403018352,-0.026240772267026, 0.20873560855118, -0.30096707680412,-0.18583550167484, 0.058639802778237,-0.26345850769132, 0.28467496801765, 0.23430751211255, 0.29959999253611, 0.15025694594835, 0.10509140460991,2.1901953171311e-008], [0.25038964300909, 0.27545800190467, 0.052539394634133,-0.21779928371594,-0.29199499098325, -0.10284837572308,-0.17935724736017, 0.29972349551921,-0.14881816217133, 0.13738993183933, -0.29924435936459,-0.18859307752492,-0.094947381576156,-0.2922703318802,-0.22073196554138, -0.055862415738288, 0.28179496831653, 0.26020840478266, 0.271141219361, 0.024088262365568, 0.24445200131555,6.5705969413844e-008],[-0.27110584051804,-0.23154377907845, 0.073469373391738, 0.29434211257483, 0.17753862829944,-0.14326589235934, 0.29963816813405,-0.11123315714461, -0.20567919493146,-0.2855154354384, 0.034953086479784,-0.25676693292523, 0.25028136066994, -0.04877294708817,-0.29170014715898, 0.19150673364858, 0.13640890921551, 0.28056612462186, 0.21973335334038,-0.10661741894362, 0.30318484246412,1.9711794487484e-007],[0.28642607315641, 0.16928558225021,-0.18648858616204,-0.27942511073761, 0.021847540061488, 0.29246663334952, -0.14991580497635,-0.2049393458244, 0.26976808553989,-0.04833873669935, 0.29822672189679, 0.12319907682396, 0.22855496284914, 0.25311977771911,-0.087260293695055, 0.30252645711633, -0.077960269901703, 0.29494699478712, 0.14972749938216,-0.2172418266432, 0.26191803854843, 5.9135384683561e-007],[-0.29604541412156,-0.093615795043362, 0.26653618528362, 0.17768338274501,-0.21078242044234,-0.24382563735737,-0.13489535514247, 0.28586635224239, 0.047041714440523, 0.30059210640025,-0.043635772807849, 0.28814356084378,-0.12827197214627, 0.25195483701828, 0.19956616896758, 0.19815266429733,-0.25290429206947, 0.30304466218869, 0.067048875518469,-0.2869489751979, 0.13426264515743,1.7740615445772e-006],[0.2997724045138, 0.010529329585474,-0.29945956996701,-0.020730757605517, 0.29888454020207, 0.030246552315071, 0.29815261209068,-0.038653480444366,-0.29743102810733,-0.045414815655835,-0.29695629339339, -0.049814003422456,-0.29703032952329,-0.050872997859757, 0.2979726839565,-0.047302340166496, -0.29995251012318, 0.30468662367482,-0.021304690993506,-0.30260959983521,-0.03767667994998, 5.3221846350884e-006],[-0.2975328640455, 0.073391318284669, 0.27943780960123,-0.14266345879735, -0.24400816473291, 0.20379309049824,-0.19274521633934,-0.25292889572571, 0.12786299611613, -0.28642739546263, 0.052281471396764,-0.30083030729363,-0.0302915892236,-0.29279112387306, 0.11504896241419,-0.25907891043924,-0.19531224885405, 0.29983790083541,-0.10785505202899, -0.26127403912685,-0.19718908228785,1.5966553905718e-005],[0.28937136749109,-0.15149756492172, -0.21001079775798, 0.26172838886742, 0.072404707316026,-0.29997502781055,-0.086344463273927, 0.25417959630784, 0.22224102365854, 0.13475044771235, 0.29543415072951,-0.026802160122866, 0.2808597846683,-0.18415349607666,-0.17649797713216,-0.28639585345436, 0.0080990412343705, 0.28860178514073,-0.18527668077985,-0.17072780047506,-0.29166248703247,4.7899661717303e-005], [-0.2754503574915, 0.21760147056151, 0.10345339081527,-0.29946742939767, 0.13383525586504, 0.19323610583142, 0.2876293399195, 0.036337031175021,-0.25855212483334, 0.24439923542285, -0.060882853744621, 0.29400427070903, 0.18022283622473, 0.14496918871154,-0.30140475022244, -0.10980398626662, 0.20741457880413, 0.27121763754183,-0.24701669623951,-0.048025168355143, -0.28993667236771, 0.00014369898515196],[0.25604691137112,-0.26646597666023, 0.021394815059487, 0.24415406858406,-0.27605195615261, 0.044219152529576,-0.2297320609106,-0.28514315691128, -0.070199103736641,-0.21097765403584,-0.29366158414507, 0.10167985276731,-0.18465151261125, 0.30052177835578,-0.14174090916846, 0.14496638778532, 0.30183883863374, 0.24805578940731, -0.28784949180191, 0.08372295141063,-0.19258086481729, 0.0004310969554559],[-0.23154722631933, 0.29421981000524,-0.14246036811486,-0.11297562145602, 0.28621266830173,-0.2517619595311, -0.035176264976952, 0.20663954490106, 0.29983280088965,-0.17859609517975, 0.069432628914052, -0.26810820890938,-0.27879526651817, 0.096262782340692, 0.15174729112892, 0.29652324356814, 0.24362068712257, 0.21960965342073,-0.30431902482361, 0.19970194534932,-0.031705990906623, 0.0012932908663677],[0.20243893270082,-0.29866418296615, 0.23833859837261,-0.053307320644792, -0.15945677512373, 0.28899807954662, 0.26838733707548, 0.10906118585558,-0.10611797249009, 0.26668110733135, 0.29164009615111,-0.16996227605917, 0.035822366365029,-0.2232506373088, 0.30196362925619, 0.23696076551916, 0.062201527738413, 0.18648521249905,-0.29503133224977, 0.27806729749601, 0.13962648969474, 0.0038798725991031],[-0.16930138848704, 0.27944699166705, -0.29207801281944, 0.20302627712225,-0.043579041217345,-0.13073879761751,-0.25975517929678, -0.29957291145642,-0.23742998642424, 0.09541925644721,-0.077923549712367, 0.22482182045925, 0.29791830353817,-0.27546840121904, 0.16708168886182, 0.0086863903565246,-0.1506734616047, 0.14938811064754,-0.26077251410494, 0.30405897995318, 0.26490587840154, 0.011639617797309], [0.13279414798389,-0.23809071129165, 0.29417735860492,-0.28965963307171, 0.22576779155574, -0.11595994325226, 0.017058209731518, 0.14621129235954, 0.24573899090656,-0.29644201609954, -0.28937140025619, 0.22722042109058, 0.12321522175635, 0.0021292738181141,-0.12555005068661, -0.22577254195383,-0.2873516281383, 0.1091086207525,-0.20444219885666, 0.27278148791337, 0.30281119655688, 0.034918853391928],[-0.093643834368896, 0.17787177852523,-0.24426546653537, 0.28628812777828,-0.29995517425576, 0.28421651678604, 0.24100987451578, 0.17498314543852, 0.092922846901844,-0.0029601017159201, 0.086348418834615,-0.16695279423071,-0.2321423795508, 0.27717759155747,-0.29964399345724,-0.29948539553781,-0.27871368618079, 0.066504809540183, -0.13080812206979, 0.19012590260606, 0.24084010950982, 0.10475656017578],[0.052629677320518, -0.10356101701719, 0.15116687464641,-0.19395937655134, 0.23065189858244,-0.26021222036678, -0.28190449923876,-0.29531816909551,-0.30038239426931, 0.29736526074001, 0.28685741951396, -0.26974034769706,-0.24713967925377, 0.22036407461323,-0.19082973660648,-0.15996991518929, -0.12912791482901, 0.022484258335635,-0.046102590542849, 0.071660312626567, 0.099432579425314, 0.31426968052735],[-0.010568003592202, 0.021045670564795,-0.031341629454407, 0.041362349112998, -0.051010827054222, 0.060184980503349, 0.068775609455734, 0.076663775908477, 0.083717418440714, -0.089787009561446,-0.094700094964361, 0.0982546940298, 0.10021192059336,-0.10028904671092, 0.098155985037105, 0.093441331040833, 0.085758917115656,-0.022015270978914, 0.042505013244744, -0.060302418430461,-0.074770860143132, 0.94280904158206]]
The equivalent computations in the
Maple environment are
> #eigenvals(K,M):
> #eigenvectors(K,M):
Heat Transfer: Finite Difference Solution
Employ a difference equation method to solve the heat transfer distribution problem in a flat plate. The interior nodal temperatures are computed given the external boundary conditions of the plate. In this example, the external nodal temperatures are varied symbolically in order to observe a range of internal nodal temperatures.
> A:=band([1, 0, 0, 0, 0, 0,1,-4,1, 0, 0, 0, 0, 0,1],21):A[8,7]:=0:A[16,15]:=0:
The external temperature fields may first be written symbolically, and then assigned values where necessary.
> T:=array(1..21,[0, 0, 0, 0, 0, 0,-t, 0, 0, 0, 0, 0, 0,-t, 0, 0, 0, 0, 0, 0,-t]);
> Tnum:=subs(t=100,evalm(T));
The solution in MATLAB environment
is
> setvar("Tnum",Tnum);
> setvar("A",A);
> evalM("C=inv(A)*Tnum'");C:=getvar("C");
The following command is the equivalent solution in the Maple environment.
> evalm(evalf(inverse(A))&*(Tnum));
Data Analysis: Fast Fourier Transform (FFT)
Import a set of experimental numerical data into Maple and analyze the set with Matlab as a numerical engine.
> restart;
> with(Matlab);
> evalM("t=0:0.001:0.6");
> evalM("x=sin(2*pi*50*t)
+ sin(2*pi*120*t)");
> evalM("y=x+2*randn(size(t))");
> data:=convert(getvar("y"),array):
> tmax:=op(2,size(data));
> evalM("Y=fft(y,512)");
> evalM("Pyy=Y.*conj(Y)/512");
> evalM("f=1000*(0:511)/512");
> freq:=convert(getvar("f"),array):
> Pyy:=convert(getvar("Pyy"),array):
> t:=convert(getvar("t"),array):
> size(data);
> size(freq);
> size(Pyy);
> plots[pointplot]([seq([t[1,i],data[1,i]],i=1..tmax)]);
> plots[pointplot]([seq([freq[1,i],Pyy[1,i]],i=1..512)],style=line);