%%%%%%%%%%%%%%%%%%%%%%%%%%
%  yl3.m   pris_varras

clear
delete yl3.txt
if exist('yl3.txt')==2, delete yl3.txt, end
if exist('yl3.ps')==2, delete yl3.ps, end

clc
% echo on
diary yl3.txt

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Elastsuskonstandid ja tihedus

imat=1;
ikoo=1;

for ikoo = 1:4
    for imat = 1:3
        if imat == 1,txmat='Materjal: teras; ',   rho=7800, E=210e9,    nu=0.3,  end
        if imat == 2,txmat='Materjal: alumiinium; ',   rho=2600, E=70e9,    nu=0.35,  end
        if imat == 3,txmat='Materjal: vask; ',   rho=8900, E=110e9,    nu=0.32,  end
        
        if ikoo == 1,     M=2000, l=.2,    a=0.015,    b=0.025,   % hea kuju ristlõikel kõigi mat korral
            txt1=sprintf('Tala: pikkus l = %g m; laius 2b = %g m; kõrgus 2a = %g m',l,2*b,2*a)
        end
        if ikoo == 2,     M=10000, l=1,    a=0.03,    b=0.05,   % normaalsed läbipainded ja paindepinged
            txt1=sprintf('Tala: pikkus l = %g m; laius 2b = %g m; kõrgus 2a = %g m',l,2*b,2*a)
        end
        if ikoo == 3,     M=10000, l=1,    a=0.015,    b=0.5,   %plaat
            txt1=sprintf('Plaat: pikkus l = %g m; laius 2b = %g m; kõrgus 2a = %g m',l,2*b,2*a)
        end
        if ikoo == 4,     M=10000, l=.5,    a=0.015,    b=0.5,   %plaat
            txt1=sprintf('Plaat: pikkus l = %g m; laius 2b = %g m; kõrgus 2a = %g m',l,2*b,2*a)
        end
%         txt2=sprintf('Koormus otstes z = 0 ja z = l: M = %g kNm',.001*M )
        txt2=sprintf('Koormus otstes x = 0 ja x = l: M = %g kNm',.001*M )
        txt3=[txmat,sprintf('E = %g GPa; nu = %g',E/1e9,nu)]
        
        V=l*2*a*2*b,   mass=rho*V, Iy= (2*a)^3*(2*b)/12,
        
        zv=0:l/10:l;    xv=-a:a/5:a;    yv=-b:b/5:b;
        yxv=ones(size(xv));
        
        %text
        figure(1), subplot(4,1,1)
        plot(0*[0:2]-.05,[0:2],'o')
        ht = text(0,0,txt1); set(ht,'fontname','times','FontSize',12,'FontAngle','italic')
        ht = text(0,1,txt2); set(ht,'fontname','times','FontSize',12,'FontAngle','italic')
        ht = text(0,2,txt3); set(ht,'fontname','times','FontSize',12,'FontAngle','italic')
        axis('ij'),axis([-.1 1.5 -.1 4]), axis('off')
        % x - z tasand
        figure(1), subplot(4,1,2)
        yy=0*yxv;
        hold off
        plot([0,0],[0,3*a],'k-',[0,1.1*l],[0,0],'k-')
        set(gca,'ytick',[-a,0,a],'xtick',[0,l])
        text(0.01*l,3*a,'\it z')
        text(1.1*l,0.25*a,'\it x')
        
        hold on,%axis('equal')
        set(gca,'ydir','reverse','xlim',[-.1*l,1.1*l])
        grid on
        % enne deformatsiooni
        % Ülemine  pind
%         za=zv; xa=-a*yxv;    plot(za,xa,'r-','linewidth',2)
        xy=-a*yxv;    plot(zv,xy,'r-','linewidth',2)
        % Alumine pind
%         zy=zv; xy=a*yxv;    plot(zy,xy,'r-','linewidth',2)
        xa=a*yxv;    plot(zv,xa,'r-','linewidth',2)
        % Vasak otspind
%         zvo=0*yxv; xvo=xv;    plot(zvo,xvo,'r-','linewidth',2)
        zvo=0*yxv;      plot(zvo,xv,'r-','linewidth',2)
        % Parem otspind
%         zpo=l*yxv; xpo=xv;    plot(zpo,xpo,'r-','linewidth',2)
        zpo=l*yxv;      plot(zpo,xv,'r-','linewidth',2)
        
        % peale deformatsiooni 
        % kõverusraadius R
        R=E*Iy/M
        % max paindepinge MPa
        sigma_m=E*a/R/10^6
        
        % Ülemine  pind
%         u=-(za.^2+nu*(xa.^2-yy.^2))./(2*R);   v=-nu*(xa.*yy)./R;   w= (xa.*za)./R;
        u=-(zv.^2+nu*(xy.^2-yy.^2))./(2*R);   w= (xy.*zv)./R;   %v=-nu*(xa.*yy)./R;
        zyd=zv+w;   xyd=xy+u;    plot(zyd,xyd,'b-','linewidth',2)
        % Alumine pind
%         u=-(zy.^2+nu*(xy.^2-yy.^2))./(2*R);   v=-nu*(xy.*yy)./R;   w= (xy.*zy)./R;
        u=-(zv.^2+nu*(xa.^2-yy.^2))./(2*R);   w= (xa.*zv)./R;   %v=-nu*(xa.*yy)./R;  
        zad=zv+w;   xad=xa+u; plot(zad,xad,'b-','linewidth',2)
        %telg
        xte=0*yxv; 
        u=-(zv.^2+nu*(xte.^2-yy.^2))./(2*R);   w= (xte.*zv)./R;
        xted=xte+u;   zted=zv+w;
        plot(zted,xted,'b--','linewidth',2)
        % Vasak otspind
%         u=-(zvo.^2+nu*(xvo.^2-yy.^2))./(2*R);   v=-nu*(xvo.*yy)./R;   w= (xvo.*zvo)./R;
        u=-(zvo.^2+nu*(xv.^2-yy.^2))./(2*R);   w= (xv.*zvo)./R;   %v=-nu*(xvo.*yy)./R;
        zvod=zvo+w;   xvod=xv+u; plot(zvod,xvod,'b-','linewidth',2)
        % Parem otspind
        u=-(zpo.^2+nu*(xv.^2-yy.^2))./(2*R);   w= (xv.*zpo)./R;   %v=-nu*(xpo.*yy)./R;
        zpod=zpo+w;   xpod=xv+u; plot(zpod,xpod,'b-','linewidth',2)
        axis('tight'),  ylimv=get(gca,'ylim');  xlimv=get(gca,'xlim'); 
        set(gca,'ylim',ylimv*1.1,'xlim',[xlimv(1)-.05*l,xlimv(2)+.05*l]);
        if ikoo >= 3,title('\it Plaadi peatasandi x-z punktide siirded ja deformeerunud kuju')
        else,title('\it Tala peatasandi x-z punktide siirded ja deformeerunud kuju')
        end
       
        %title(txtkoo)
        times12

        % tala otsa otsa siire
        subplot(4,1,3)
        hold off
        plot([0,0],[0,1.5*a],'k-',[0,1.2*b],[0,0],'k-')
        text(0,1.5*a,'\it z')
        text(1.2*b,0.25*a,'\it y')
%         set(gca,'xdir','reverse','ydir','reverse','xlim',[-1.1*b,1.21*b],'ylim',[-1.1*a,1.5*a])
        set(gca,'ydir','reverse','xlim',[-1.1*b,1.21*b],'ylim',[-1.1*a,1.5*a])
        set(gca,'ytick',[-a,0,a],'xtick',[-b,0,b])
        hold on,%axis('equal')
%         title('{\it Tala otsa z = l siirded ja deformeerunud kuju}')
        title('{\it Tala otsa x = l siirded ja deformeerunud kuju}')
        if ikoo >= 3,title('{\it Plaadi serva x = l siirded ja deformeerunud kuju}')
        else,title('{\it Tala otsa x = l siirded ja deformeerunud kuju}')
        end
        
        % set(gca,'ydir','reverse','xlim',[-.01*l,1.1*l])
        grid on
        zz=l*yxv;
        % Enne deformatsiooni
        % Ülemine serv
%         xyv=-a*yxv; yyv=yv; plot(yyv,xyv,'r-','linewidth',2),
        xyv=-a*yxv;  plot(yv,xyv,'r-','linewidth',2),
        % Alumine serv
%         xav=a*yxv;  yav=yv; plot(yav,xav,'r-','linewidth',2)
        xav=a*yxv; plot(yv,xav,'r-','linewidth',2)
        % Vasak serv
%         yvv=b*yxv;  xvv=xv; plot(yvv,xvv,'r-','linewidth',2)
        yvv=b*yxv; plot(yvv,xv,'r-','linewidth',2)
        % Parem serv
%         ypv=-b*yxv;  xpv=xv; plot(ypv,xpv,'r-','linewidth',2)
        ypv=-b*yxv; plot(ypv,xv,'r-','linewidth',2)
        
        % Peale deformatsiooni
        % Ülemine serv
%         u=-(zz.^2+nu*(xyv.^2-yyv.^2))./(2*R);   v=-nu*(xyv.*yyv)./R;   w= (xyv.*zz)./R;
%         xyvd=xyv+u; yyvd=yyv+v;
        u=-(zz.^2+nu*(xyv.^2-yv.^2))./(2*R);   v=-nu*(xyv.*yv)./R;%   w= (xyv.*zz)./R;
        xyvd=xyv+u; yyvd=yv+v;
        plot(yyvd,xyvd,'b-','linewidth',2),
        % Alumine serv
        % xav=a*yxv;  yav=yv; 
%         u=-(zz.^2+nu*(xav.^2-yav.^2))./(2*R);   v=-nu*(xav.*yav)./R;   w= (xav.*zz)./R;
%         xavd=xav+u; yavd=yav+v;
        u=-(zz.^2+nu*(xav.^2-yv.^2))./(2*R);   v=-nu*(xav.*yv)./R;%   w= (xav.*zz)./R;
        xavd=xav+u; yavd=yv+v;
        plot(yavd,xavd,'b-','linewidth',2),
        % Vasak serv
        % yvv=b*yxv;  xvv=xv; 
%         u=-(zz.^2+nu*(xvv.^2-yvv.^2))./(2*R);   v=-nu*(xvv.*yvv)./R;   w= (xvv.*zz)./R;
%         xvvd=xvv+u; yvvd=yvv+v;
        u=-(zz.^2+nu*(xv.^2-yvv.^2))./(2*R);   v=-nu*(xv.*yvv)./R;%   w= (xvv.*zz)./R;
        xvvd=xv+u; yvvd=yvv+v;
        plot(yvvd,xvvd,'b-','linewidth',2),
        % plot(yvv,xvv,'r-','linewidth',2)
        % Parem serv
        % ypv=-b*yxv;  xpv=xv; 
%         u=-(zz.^2+nu*(xpv.^2-ypv.^2))./(2*R);   v=-nu*(xpv.*ypv)./R;   w= (xpv.*zz)./R;
%         xpvd=xpv+u; ypvd=ypv+v;
        u=-(zz.^2+nu*(xv.^2-ypv.^2))./(2*R);   v=-nu*(xv.*ypv)./R;%   w= (xpv.*zz)./R;
        xpvd=xv+u; ypvd=ypv+v;
        plot(ypvd,xpvd,'b-','linewidth',2),
        % plot(ypv,xpv,'r-','linewidth',2)
        
        % ristlõike z=l punktide siirded
%         xov=[0,a,a,a,-a,-a,-a],    yov=[0,b,0,-b,-b,0,b],    zov=l*[1 1 1 1 1 1 1],
        xov=[0,a,a,a,-a,-a,-a],    yov=[0,-b,0,b,-b,0,b],    zov=l*[1 1 1 1 1 1 1],
        plot(yov,xov,'ro')
        
        u=-(zov.^2+nu*(xov.^2-yov.^2))./(2*R),   v=-nu*(xov.*yov)./R,   w= (xov.*zov)./R,
        eps_z=xov./R
        xovd=xov+u; yovd=yov+v; zovd=zov+w;
        plot(yovd,xovd,'bo')
        axis('tight'),  ylimv=get(gca,'ylim');  xlimv=get(gca,'xlim'); 
        set(gca,'ylim',ylimv*1.1,'xlim',xlimv*1.1);
        
        times12
        
        subplot(4,1,4)
        plot(0*[1:7]-.05,[1:7],'o')
        for itx=1:7
%             txtt=sprintf('x = %6.3f; y = %6.3f; u = %9.6f; v = %11.8f',xov(itx),yov(itx),u(itx),v(itx))
%             txtt=sprintf('x = %6.3f; y = %6.3f; u = %9.6f; v = %11.8f; w = %11.8f',xov(itx),yov(itx),u(itx),v(itx),w(itx))
%             txtt=sprintf('z = %6.3f; y = %6.3f; w = %9.6f; v = %11.8f; u = %11.8f',xov(itx),yov(itx),u(itx),v(itx),w(itx))
            txtt=sprintf('y = %6.3f; z = %6.3f; u = %9.6f; v = %11.8f; w = %11.8f',yov(itx),xov(itx),w(itx),v(itx),u(itx))
            ht = text(0,itx,txtt); set(ht,'fontname','times','FontSize',12,'FontAngle','italic')
        end
%         title('\it Punktide (x, y) siirded (u, v) lõikes z = l')
        title('\it Punktide (y, z) siirded (u, v, w) lõikes x = l')
        axis('ij'),axis([-.1 1.5 1-.1 7]),axis('off')
        times12
        diary off
        
        subplot(4,1,1)
        txttt=sprintf('NB! Maksimaalse vertikaalsiirde ja paksuse suhe on %4.2f',abs(u(1))/2/a)
        ht=text(-.1,3,txttt)
        set(ht,'fontname','times','FontSize',12,'FontAngle','italic')
        pikk
        print -dpsc yl3 -append
%         pause
    end
end
return



% enne deformatsiooni

hold off
plot(yv,xav,'r-',yv,xyv,'r-')
hold on
plot(yvv,xv,'r-',ypv,xv,'r-')
plot([0,0],[0,1.5*a],'k-',[0,1.5*b],[0,0],'k-')
set(gca,'xdir','reverse','ydir','reverse')
xlabel('y'),ylabel('x')

% tippude ja y=0 siirded ning uued koordinaadid z=0 jaoks
z=0,
x=-a, y=b, u=-(z^2+nu*(x^2-y^2))/2/R,   v=-nu*x*y/R,    xd=x+u, yd=y+v, plot(yd,xd,'.')


% alumine külg  x=-a*; y


