Page 4 - Demo
P. 4


                                    Planar Truss Example for Comrel Add-on RCP Consult, 2022-2025 Page 4fc(c) = [];// f = equivalent nodal force vector// q = equilibrium nodal force vector// a = displacements//| qd | | Kcc Kcd || ac | | fd |//| | = | || | - | |//| qc | | Kdc Kdd || ad | | fc |//! Solve the system of equationsKcc = K(c,c); Kcd = K(c,d);Kdc = K(d,c); Kdd = K(d,d);ac = [0; 0; 0]; // displacements for c are 0ad = Kdd\\(fc-Kdc*ac); // = linsolve(Kdd, fc-Kdc*ac)qd = Kcc*ac + Kcd*ad;//! Final displacementsa = zeros(ndof,1); q = zeros(ndof,1);a(c) = ac; q(c) = qd;a(d) = ad; // q(d) = qc = 0//! Axial loads in barsN = zeros(nfe,1);for e = 1:nfe N(e) = k(e)*[-1 0 1 0]*T{e}*a(LM{e});end// Return value of script (function)lsfval = a(8); // vertical deflection at bottom center (N04)//! Visualizationif StrurelPlot then // begin of plot block if(StrurelMode == 0 || StrurelMode == 2) then // X and Y coordinates in m XY = [0 0; 4 0; 8 0; 12 0; 16 0; 20 0; 24 0; 22 2; 18 2; 14 2; 10 2; 6 2; 2 2]; // deflection vector b=matrix(a,[2,nnp])'; // forces with scale factor 0.0005 fc = zeros(ndof,1); fc(16:2:26) = P; d=matrix(fc,[2,nnp])'*0.00005; // deformed coordinates with scale factor 2. DEF = XY + b*2 // resolution of screen pxl = get(0, \_px\ select StrurelMode case int32(0) tit='Planar Truss - Deterministic Solution'; // 0 - initial deterministic solution nf=0; case int32(2) tit='Planar Truss - Stochastic Solution'; // 2 - final stochastic solution nf=1; end //! Create 3 plots for f = 1:3 nf=f+nf; switch(f) case 1 // plot for initial and deformed states scf(nf); figure(nf,'Name',tit,'position',[pxl(3)/4 pxl(4)/4 pxl(3)/2 pxl(4)/2]); // plot frame replot([-2 -2 26 10]); mtlb_axis('equal'); xgrid(2); // set a main subtitle of plot xstring(8.0,8.0,'$\\textcolor{blue}{Initial}\\textcolor{black}\\,and\\,\\textcolor{red}{deformed}\\textcolor{black}\\,{states}
   1   2   3   4   5   6   7   8   9   10

 

 

 

 

 

); gce().font_size=6; // plot initial and deformed states of truss for e = 1:nfe plot(XY(IEN(e,:),1), XY(IEN(e,:),2),'b-','LineWidth',2); // blue color for initial state plot(DEF(IEN(e,:),1), DEF(IEN(e,:),2),'r-','LineWidth',2); // red color for deformed state x=(XY(IEN(e,1),1)+XY(IEN(e,2),1))/2; y=(XY(IEN(e,1),2)+XY(IEN(e,2),2))/2; xstring(x, y, strcat(['R',string(e)])); gce().font_size=3; // rod number in the middle of rod length end // plot nodal numbers plot(XY(:,1), XY(:,2), 'r*'); for e = 1:nnp xstring(XY(e,1), XY(e,2), strcat(['N',string(e)])); gce().font_size=3; end // value of vertical deflection in node N04 xstring(DEF(4,1), DEF(4,2)-0.5, sprintf('$U\\\\,=\\\\,%g m
   1   2   3   4   5   6   7   8   9   10

 

 

 

 

 

,b(4,2))); gce().font_size=3; // plot vertical forces n=0; for i = 1:nnp if(d(i,2) > 0.001) xarrows([XY(i,1)+d(i,1) XY(i,1)],[XY(i,2)+d(i,2) XY(i,2)],5,1); gce().thickness=2; // single vector n=n+1; Pn=strcat(['$P',string(n)]); xstring(XY(i,1)+0.1+d(i,1), XY(i,2)+d(i,2), strcat([Pn,sprintf('=%g\\\\,N
   1   2   3   4   5   6   7   8   9   10

 

 

 

 

 

,d(i,2)*20000)])); gce().font_size=2; // force value end end case 2 // plot for internal member forces N scf(nf); figure(nf,'Name',tit,'position',[pxl(3)/4 pxl(4)/4 pxl(3)/2 pxl(4)/2]); // plot frame replot([-2 -2 26 10]); mtlb_axis('equal'); xgrid(2); // set a main subtitle of plot xstring(8.0,8.0,'$Internal\\,member\\,forces\\,[N]
   1   2   3   4   5   6   7   8   9   10

 

 

 

 

 

); gce().font_size=6;
   1   2   3   4   5   6   7   8   9   10