Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
repair script

Subject: repair script

From: wahyoe Unggul

Date: 17 Jun, 2010 08:01:07

Message: 1 of 4

can help me repair me script
this script, very slow analysing
thanks before
___________________________________________________________________
function [Aex,Bex,Cex]=extract(K,index)
% Purposes
% Extract matrix m x m to vector ( m x m ) x 1 with
% index of row and colomn informatioan
% input argument, K ( m x m ) and index = ( 1 x m )
% Examples
% K=[ 11 12 13 14; 21 22 23 24; 31 32 33 34; 41 42 43 44];
% index=[1 2 3 4]
m=size(K,1);
ind=zeros(m,m);Aex=zeros(m*m,1);Bex=Aex;Cex=Aex;
for i=1:m;
    ind(i,:)=index;
end;
for i=1:m;
    for j=1:m;
        im=j+m*(i-1);
        Aex(im)=K(i,j);
        Bex(im)=ind(j,i);
        Cex(im)=ind(i,j);
    end;
end;
y = [Aex Bex Cex];
fid = fopen('scratch_file.txt','a+');
for i=1:m*m;
    fprintf(fid,'%12.8f %6.2f %6.2f\n',y(i,:));
end;
clear K index;
fclose(fid);
____________________________________________________________________
function [S,Sm,SmS,Cx,Cy,Cxz,RT,L,A,Joint,Xj,Xk,Yj,Yk,...
            Zj,Zk]=p3d_stiff(prop,element,coord,index)
        
Joint=coord(:,1);
m=size(element,1);

% Property i E G Ix Iy Iz Ax
E= prop(element(:,4),2); % modulus elasticity
G= prop(element(:,4),3); %
Ix= prop(element(:,4),4); %
Iy= prop(element(:,4),5); %
Iz= prop(element(:,4),6); %
A= prop(element(:,4),7); %

% skew parameter
iA = element(:,5);
Xp = element(:,6);
Yp = element(:,7);
Zp = element(:,8);

Xj=zeros(1,m);Xk=Xj;Yj=Xj;Yk=Xj;Zk=Xj;Zj=Xj;
for i=1:m;
  ij=find(Joint==element(i,2));
  ik=find(Joint==element(i,3));
  Xj(i)=coord(ij,2);
  Xk(i)=coord(ik,2);
  Yj(i)=coord(ij,3);
  Yk(i)=coord(ik,3);
  Zj(i)=coord(ij,4);
  Zk(i)=coord(ik,4);
end

% Calculate length of element
L=sqrt((Xk-Xj).^2+(Yk-Yj).^2+(Zk-Zj).^2);
Cx=(Xk-Xj)./L;
Cy=(Yk-Yj)./L;
Cz=(Zk-Zj)./L;
Cxz=sqrt(Cx.^2+Cz.^2); % calculate parameter CXZ

% Perform Stiffness matrix 6 x 6 x m element
SmS=zeros(12,12,m);
Sm=SmS;
RT=SmS;

for i=1:m;
    
    RT(:,:,i)=p3d_RT(element,Xj,Yj,Zj,Cx,Cy,Cz,Cxz,i,m);

    % Perform SmS matrix
    Sm11=E(i)*A(i)/L(i);
    Sm22=12*E(i)*Iz(i)/L(i)^3;
    Sm26=6*E(i)*Iz(i)/L(i)^2;
    Sm33=12*E(i)*Iy(i)/L(i)^3;
    Sm35=6*E(i)*Iy(i)/L(i)^2;
    Sm44=G(i)*Ix(i)/L(i);
    Sm55=4*E(i)*Iy(i)/L(i);
    Sm511=2*E(i)*Iy(i)/L(i);
    Sm66=4*E(i)*Iz(i)/L(i);
    Sm612=2*E(i)*Iz(i)/L(i);
    
    SmS(:,:,i)= ...
    [ Sm11 0 0 0 0 0 -Sm11 0 0 0 0 0
         0 Sm22 0 0 0 Sm26 0 -Sm22 0 0 0 Sm26
         0 0 Sm33 0 -Sm35 0 0 0 -Sm33 0 -Sm35 0
         0 0 0 Sm44 0 0 0 0 0 -Sm44 0 0
         0 0 -Sm35 0 Sm55 0 0 0 Sm35 0 Sm511 0
         0 Sm26 0 0 0 Sm66 0 -Sm26 0 0 0 Sm612
     -Sm11 0 0 0 0 0 Sm11 0 0 0 0 0
         0 -Sm22 0 0 0 -Sm26 0 Sm22 0 0 0 -Sm26
         0 0 -Sm33 0 Sm35 0 0 0 Sm33 0 Sm35 0
         0 0 0 -Sm44 0 0 0 0 0 Sm44 0 0
         0 0 -Sm35 0 Sm511 0 0 0 Sm35 0 Sm55 0
         0 Sm26 0 0 0 Sm612 0 -Sm26 0 0 0 Sm66 ]
              
    Sm(:,:,i)=RT(:,:,i).'*SmS(:,:,i)*RT(:,:,i);
    [Aex,Bex,Cex]=extract(Sm(:,:,i),index(i,:));
end;

disp('assembly stiffness matrix');
S=assembly;
____________________________________________________________________
% Purposes
% This function assembly matrix base on row and col.
% information
% For example take matrices
% A1=[0.178857384;0.57896014;0.635206968;0.437880448]
% A2=[0.389532694;0.449666857;0.821290467;0.105003395]
% A3=[0.164485174;0.351283287;0.682633129;0.956467906]
% with index
% iA1=[1 1;1 2;2 1;2 2]
% iA2=[2 2;2 3;3 2;3 3]
% iA3=[3 3;3 4;4 3;4 4]
% The result is
% A=[0.178857384 0.57896014 0 0
% 0.635206968 0.827413142 0.449666857 0
% 0 0.821290467 0.269488569 0.351283287
% 0 0 0.682633129 0.956467906]
% tA=[A1 iA1;A2 iA2;A3 iA3]

function [A]=assembly;

load scratch_file.txt;
tA=scratch_file;clear scratch_file;
m=max(tA(:,2));
A=zeros(m,m);
%B=zeros(size(tA));
B=A;C=A;
for i=1:length(tA);
    C=A;
   B(tA(i,2),tA(i,3))=tA(i,1);
  A(tA(i,2),tA(i,3))=B(tA(i,2),tA(i,3))+C(tA(i,2),tA(i,3));
end;
delete scratch_file.txt;
_____________________________________________________________
function [DF,AR,AM]=analysis_result(element,dof,index,...
                   IF,IR,S,SmS,JL,AML,RT,Support,type)
clear Sff Srf;

ndof=length([IF IR]); % find number degree of freedom

% Perform Sff matrix
Sff=S(IF,IF);

% Perform Sff matrix
Srf=S(IR,IF);

% create joint load matrix (AJ)
i=1:size(JL,1);
AJ=zeros(1,ndof);

switch type;
    case{'t2d','T2D'};
    AJ(dof(JL(i),2))=JL(i,2);
    AJ(dof(JL(i),3))=JL(i,3);
    case{'p2d','P2D','t3d','T3D'};
      AJ(dof(JL(i),2))=JL(i,2);
      AJ(dof(JL(i),3))=JL(i,3);
      AJ(dof(JL(i),4))=JL(i,4);
    case{'p3d','P3D'};
      AJ(dof(JL(i),2))=JL(i,2);
      AJ(dof(JL(i),3))=JL(i,3);
      AJ(dof(JL(i),4))=JL(i,4);
      AJ(dof(JL(i),5))=JL(i,5);
      AJ(dof(JL(i),6))=JL(i,6);
      AJ(dof(JL(i),7))=JL(i,7);
end;
% create joint load ekuivalen matrix AE
[mi,ni]=size(index);
% transpose to .. x m matrix (m=number of element)
AMLT=AML';

AE=zeros(ndof,1);

for i=1:size(element,1);
    Ji=index(i,:);
    switch type;
    case{'t2d','T2D'};
      AMLi=[AMLT(1,i);AMLT(2,i);AMLT(3,i);AMLT(4,i)];
    case{'p2d','P2D','t3d','T3D'};
      AMLi=[ AMLT(1,i); AMLT(2,i); AMLT(3,i);
             AMLT(4,i); AMLT(5,i); AMLT(6,i)];
    case{'p3d','P3D'};
      AMLi=[ AMLT(1,i) ; AMLT(2,i) ; AMLT(3,i);
             AMLT(4,i) ; AMLT(5,i) ; AMLT(6,i);
             AMLT(7,i) ; AMLT(8,i) ; AMLT(9,i);
             AMLT(10,i); AMLT(11,i); AMLT(12,i)];
    end;
   AE(Ji)=AE(Ji)-RT(:,:,i)'*AMLi;
end;

AE=AE';

% Calculate support reaction (AR) and joint displacement (DF)
AC=AJ+AE;
AFC=AC(IF)';
ARC=AC(IR)';
DF=Sff\AFC;
AR=-ARC+Srf*DF;

% Calculate member forces
Dj=zeros(1,ndof);
AM=zeros(ni,mi);
Dj(IF)=DF;

for i=1:size(element,1);
   DM=RT(:,:,i)*Dj(index(i,:))';
   AM(:,i)=AML(i,:)'+SmS(:,:,i)*DM;
end;

AM=AM.';
%

Subject: repair script

From: us

Date: 17 Jun, 2010 08:14:07

Message: 2 of 4

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvcko3$dis$1@fred.mathworks.com>...
> can help me repair me script
> this script, very slow analysing
> thanks before

a hint:
- use the profiler to identify the bottleneck(s) in your program...
- then, come back to CSSM and ask for help re possible code alternatives

     help profile;

us

Subject: repair script

From: wahyoe Unggul

Date: 17 Jun, 2010 08:56:04

Message: 3 of 4

"us " <us@neurol.unizh.ch> wrote in message <hvclge$3la$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvcko3$dis$1@fred.mathworks.com>...
> > can help me repair me script
> > this script, very slow analysing
> > thanks before
>
> a hint:
> - use the profiler to identify the bottleneck(s) in your program...
> - then, come back to CSSM and ask for help re possible code alternatives
>
> help profile;
>
> us
I have sent example to your email
pliss checking in your email (us@neurol.unizh.ch) from wahyoe_slipnot@yahoo.co.id

Subject: repair script

From: us

Date: 17 Jun, 2010 09:21:05

Message: 4 of 4

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvcnv4$7u4$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <hvclge$3la$1@fred.mathworks.com>...
> > "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvcko3$dis$1@fred.mathworks.com>...
> > > can help me repair me script
> > > this script, very slow analysing
> > > thanks before
> >
> > a hint:
> > - use the profiler to identify the bottleneck(s) in your program...
> > - then, come back to CSSM and ask for help re possible code alternatives
> >
> > help profile;
> >
> > us
> I have sent example to your email
> pliss checking in your email (us@neurol.unizh.ch) from wahyoe_slipnot@yahoo.co.id

do NOT do that...
stay in this NG...

us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us