I need to do 2 plots
Afficher commentaires plus anciens
First plot between time (t)and consoledation settlement(Se)
Second plot between time and total settelment (Se+Scplot)
But it keeps telling me an error about unmatching matrixes in the U loop
The problem is that bothe Seplot and Se depends on time.
Note: I can put any values for time and the relation should be a curve Below is the code
clc;
disp('This code determines stress increment distribution ,immediate ');
disp('settlement ,consolidation settlelment and total settlelment for ');
disp('various area shapes');
disp('This code determines the variation of total settlement vs.time ');
disp('----------------------------------------------------------------');
disp('Codes of the loaded area shapes are ');
disp('circle=0');
disp('square=1');
disp('rectangular=2');
disp('strip=3');
disp('----------------------------------------------------------------');
%code=input('enter your loaded area code=');
code=1;
while(0)
if code<0||code>3
disp('Code that you entered is not in the range of 0 and 3');
disp('Run the program with appropriate codes that are between 0 and 3');
else
break
end
end
disp('----------------------------------------------------------------');
%qa=input('insert q(all) (KN/m^2)=');
qa=210;
%p=input('insert axial load (KN) =');
p=2460;
%FS=input('range of FS is (2-4),choose yours =');
FS=3;
while FS<2 || FS>4
FS= input('your FS is out of range ,insert FS (2-4)');
end
qu=qa*FS;
disp('----------------------------------------------------------------');
disp('Es of sand =7000 KN/m^2');
disp('angle of friction of sand=37 deg');
disp('angle of friction of clay=23 deg');
disp('----------------------------------------------------------------');
%n=input('number of layers');
N=3;
%for i=1:n
%h(i)=input('insert depth of the layer(m)= ');
%Es(i)=input('insert modulus of elasticity of the layer(KN/m^2)=');
%uw(i)=input('insert unit weight of the layer(KN/m^3)= ');
%o(i)=input('insert angle of friction for the layer =');
%c(i)=input('cohesion of the layers = ');
%end
h=[2.5 0.5 2.5];
Es=[7000 6000 6000];
uw=[16 17.5 16];
o=[37 37 23];
c=[0 0 15];
%df=input('insert foundation depth (m)=');
df=1;
%GWT=input('insert total ground water level');
GWT=3;
gwt=sum(h(1:N))-GWT;
%GWTf=input('insert ground water level from the foundation base(m)= ');
GWTf=0;
%y=input('insert number of layers above the foundation base from top to bottom ');
%for i=1:y
%dlaf(i)=input('insrt depth of layer above foundation from top to bottom (m) = ');
%uwf(i)=input('insert unit weight of layer above foundation from top to bottom (KN/m^3)= ');
%end
y=1;
dlaf=1;
uwf=16;
%for i=1:2
%res=sum(dlaf(i).*uwf(i));
res=dlaf*uwf;
%end
qd=res-(GWTf*9.81);
disp(['effective stress at the foundation base = ' num2str(qd) ' N/mm2 ' ]);
r=N-y;
%dlbf(i)=input('insert depth of layer below the foundation from top to bottom (m) =');
dlbf=[1.5 0.5 2.5];
B=0.3;
i=1;
er=0.02;
%end
if i==1
while B>=0.3 && B<=dlbf(i) && er>0.001
Bold=B;
if code==0
k1=1.3;
k2=0.3;
elseif code==1
k1=1.3;
k2=0.4;
elseif code==2
L=B;
k1=1+(0.2*(B\L));
k2=0.5-(0.1*(B\L));
else
k1=1;
k2=0.5;
end
for w=1:y
if gwt<=df
uw(i)=uw(i)-9.81;
elseif gwt>df && gwt<(df+B)
uw(i)=uw(i)-9.81*(1-((gwt-df)/B));
end
end
Nq=exp(pi*(tan(o(i))))*(tan(45+(o(i)/2)))^2;
Nc=(Nq-1)*atan(o(i));
Nuw=(Nq-1)*(tan(1.4*o(i)));
if o(i)~=0
Nc=(Nq-1)./tan(o(i));
else
Nc=5.7;
end
B=(qu-k1.*c(i).*Nc-qd.*Nq)./(k2.*uw(i).*Nuw);
er=(B-Bold)./B;
end
end
B=abs(B);
i=i+1;
g=y+1;
%layerB is the order of the layer at which the B interscts.
while B>=0.3 && B<sum(h(g:N)) && er>0.001
for i=g:N
Bold=B;
if code==0
k1=1.3;
k2=0.3;
elseif code==1
k1=1.3;
k2=0.4;
elseif code==2
k1=1+(0.2*(B\l));
k2=0.5-(0.1*(B\l));
else
k1=1;
k2=0.5;
end
for ji=g:N
if sum(h(g:ji))>B
layerB=ji;
end
end
m=(sum(h(g:i)))-B;
v=h(layerB)-m;
h(layerB)=v;
xxx=r+1;
hh(layerB)=xxx;
for ij=g:layerB
if ij<layerB
hh(ij)=h(ij);
end
end
for ii=g:layerB
w(ii)=hh(ii)/B;
end
c1=sum(w(g:layerB).*c(g:layerB));
o1=sum(w(g:layerB).*o(g:layerB));
uw1=sum(uw(g:layerB).*w(g:layerB));
if gwt<=df
uw1=uw1-9.81;
elseif gwt>df && gwt<(df+B)
uw1=uw1-9.81.*(1-((gwt-df)./B));
end
aq=exp(pi.*(0.75-o1./360)*tan(o1));
Nq=sqrt(aq)./(2.*sqrt(cos(45+o1./2)));
Nuw=(2.*(Nq+1).*tan(o1))/(1+(0.4.*sin(4.*o1)));
if o1~=0
Nc=(Nq-1)/tan(o1);
else
Nc=5.7;
end
B=(qu-k1.*c1.*Nc-qd.*Nq)/(k2.*uw1.*Nuw);
er=abs((B-Bold)/B);
end
end
disp(['B=' num2str(B) ' m ']);
disp('----------------------------------------------------------------');
disp('do you want to insert the foundation load in terms of axial');
disp('load or in terms of axial load plus weight of foundation');
disp('axil= 1 , axil+weight of foundation= 0 ');
%ss=input('insert your answer=');
ss=1;
i=1;
if ss==1
if code==1
L=B;
a=B*L;
disp(['L= ' num2str(L) ' m ']);
disp(['A= ' num2str(a) ' m^2 ']);
wf=(p/a)-9.81*GWTf;
m=B/sum(h(i:N));
n=L/sum(h(i:N));
aa=2*m*n*(m^2+n^2+1)^0.5;
bb=m^2+n^2-m^2*n^2+1;
cc=(m^2+n^2+2)/(m^2+n^2+1);
dd=2*m*n*((m^2+n^2+1)^0.5);
ee=m^2+n^2-m^2*n^2+1;
Ir=(1/(4*pi))*((aa/bb)*cc+atan(dd/ee));
seg=wf*Ir;
disp(['stress increement at the last layer= ' num2str(seg) ' KN/m^2 ']);
%t=input('insert number of years to calculate the total settelment');
t=3;
%nsl=input('insert number of NONE CLAY layers below foundation base');
nsl=2;
for i=1:nsl
%osl(i)=input('insert orders of NONE CLAY layers below foundation base ');
end
osl=[1 2];
rr=r+1;
xx=0;
yy=0;
for iii=1:length(dlbf)
if xx==0 && yy==0
if sum (dlbf(1:iii))>=(B/2)
layern=iii;
xx=sum(dlbf(1:layern))-(B/2);
yy=dlbf(layern)-xx;
z(layern)=sum(dlbf(1:layern-1))-yy/2;
z(layern+1)=sum(dlbf(1:layern-1))+yy-(xx/2);
disp(['layern= ' num2str(layern)]);
disp(['hight of layern= ' num2str(dlbf(layern))]);
disp(['xx = ' num2str(xx)]);
disp(['z(layern)=' num2str(z(layern))]);
disp(['z(layern+1)=' num2str(z(layern+1))]);
disp(['yy = ' num2str(yy)]);
for i=1:rr
if i~=layern &&i~=layern+1
z(i)=sum(dlbf(1:i))-(dlbf(i)/2);
end
end
z(rr+1)=sum(dlbf(1:rr))-(dlbf(rr)/2);
end
end
disp(['z=' num2str(z) ]);
for i=rr+1
if i==osl
if z(i+1)>=0 && z(i+1)<=(B/2)
Iz=0.1+(z(i+1)./B).*(2.*0.5-0.2);
end
if z(i+1)>(B/2) && z(i+1)<(2*B)
Iz=0.667.*0.5.*(2-(z(i+1)./B));
end
end
end
disp(['Iz= ' num2str(Iz)] );
end
end
C1=1-0.5.*(qd./(wf-qd));
C2=1+0.2.*log((linspace(1,t,100)./0.1));
C3=1.03-0.03*(L./B);
if C3<0.73
C3=0.73;
end
X=sum((z(i).*Iz(i))./Es(ocl));
disp(['X = ' num2str(X)]);
Se=C1.*C2.*C3.*(wf-qd).*X;
gg=input('Flexible foundation =1,Rigid Foundation=0');
if gg==0
Se=(0.93).*Se;
end
disp(['elastic settelment (m) = ' num2str(Se)]);
disp('-----------------------------------------------------');
%ocl=input('insert orders of clay layers as a vector ');
ocl=[2 3];
%eo=input('insert void ratio of clay layer');
eo=[0.5 0.5];
%Ms=input ('insert poissons ratio of clay= ');
Ms=[0.5 0.5];
%disp('Normally consolidated clay ----> OCR=1')
%OCR=input('insert over consoloidation ratio of clay layer');
OCR=1;
%if OCR==1
%Cr=input('insert recompretion index of clay layer');
Sc=(Cr./(1+eo)).*h(ocl).*log(OCR);
%else
%Cc=input('insert compretion index of clay layer');
%Sc=(Cc./(1+eo)).*h(ocl).*log(OCR);
%end
%Cv=input('insert coffetiont of consoledation Cv ');
Cv=0.002;
Scplot=zeros([1,9]);
for U=0.1:0.1:0.9
if U==0.1
Tv=0.008;
Scplot(1)=Sc.*U;
end
if U==0.2
Tv=0.031;
Scplot(2)=Sc.*U;
end
if U==0.3
Tv=0.071;
Scplot(3)=Sc.*U;
end
if U==0.4
Tv=0.126;
Scplot(4)=Sc.*U;
end
if U==0.5
Tv=0.197;
Scplot(5)=Sc.*U;
end
if U==0.6
Tv=0.287;
Scplot(6)=Sc.*U;
end
if U==0.7
Tv=0.403;
Scplot(7)=Sc.*U;
end
if U==0.8
Tv=0.567;
Scplot(8)=Sc.*U;
end
if U==0.9
Tv=0.848;
Scplot(9)=Sc.*U;
end
end
disp(['Scplot' num2str(Scplot)']);
opl=input('insert order of nonepermiable layers');
while i<n
if ocl(i)==opl(i+1)
HD(i)=h(i);
else
HD=h(i)./2;
end
i=i+1;
end
tc=(Tv.*(HD(i).^2)./Cv);
plot(t,Scplot,'r-');
xlabel('Time (s)')
ylabel('Sc(m)')
title ('Sc vs. time')
St=Sc(nsl)+Se;
disp(St);
plot(t,St,'r-',[0 t],[Sc(i) Sc(i+1)],'b--',[0 t],[Se(i) Se(i+1)],'k--');
xlabel('Time (s)')
ylabel('St(m)')
title ('St vs. time')
legend('St','Sc','Se')
end
1 commentaire
Image Analyst
le 28 Déc 2015
You can learn how to format your code here: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup, though in this case, it's probably best just to attach the m-file with the paperclip icon since there is so much code.
Réponses (1)
Walter Roberson
le 28 Déc 2015
Undefined function or variable 'z'.
This occurs because you only assign to z inside your for loop and multiple "if" conditions need to be true for an assignment to be made. You should get in the habit of assigning something to your variables that are written to conditionally, even if it is z=[]; (and then make sure you test the size before relying on elements being there.)
4 commentaires
saja Alawneh
le 28 Déc 2015
Walter Roberson
le 28 Déc 2015
I copied the code and ran it, and it gave me the above error message right after the output
stress increement at the last layer= 24.97 KN/m^2
Nothing is being stored in your z. If you are not getting that error then you might potentially already have a z stored in your workspace.
pinaki adak
le 24 Fév 2023
PLease share the complete code without error. I think Mr.Saja has initiated a good code . Please share final one . It will help us
Walter Roberson
le 25 Fév 2023
The calculated B is 3.7345
dlbf=[1.5 0.5 2.5];
Notice the first entry 1.5 is not greater than 3.7345/2 -- so the first time,
if sum (dlbf(1:iii))>=(B/2)
is false. The body of the if is not executed, so nothing has been stored into z yet.
After the end of that if there is
disp(['z=' num2str(z) ]);
but nothing has been assigned to z yet, so that statement fails.
I cannot say what the "correct" way to repair the code is, as I am not familiar with the algorithm being used.
It seems to me, though, that if z has not been assigned to at all yet, that it does not make sense to display z, and it probably does not make sense to go on to the calculations after that, which depend upon z.
My suspicion is that the prior loop should be ended before that line that depends upon z. That way z would get assigned to if there is at least one case where the cumulative sum of dlbf is >= B/2 . Really the code should be designed to detect the case where z never gets assigned to at all (the plane is never met).
Catégories
En savoir plus sur Numbers and Precision dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!