Global Flag

Dear All
I am using flag in my code and when I run the code with these set of parameters
HenXoma(1, 9.81, 0.017, 1, 8.8, 15.2, 1, 1, 0, 0, 2, 4, 0, 36.9, 15.2)
I got a solution of 30.2 (this number is just for explaining)
Then When I am changing the fourth input parameter which is =(1) to (0)(lets call this parameter Yw), I got the same solution (30.2). It should be different solution.
After debugging I found that Matlab took the previous value of Yw as (1) not the new value (0). Also I made clear in the command window to ensure that the work space is cleared.but I got the same answer I appreciate any useful suggestion and thanks for your help.

 采纳的回答

Image Analyst
Image Analyst 2012-4-17

0 个投票

I'd say that Yw is not used, or has no effect, in the internal code of HenXoma (which we can't see because you didn't post it.) Why don't you post it.
If Yw is a global variable (I assume that's what "Glabal" means to you), you don't need to pass it via the argument list, you just declare it global inside the function.

3 个评论

Bestun
Bestun 2012-4-17
function HenXoma(flag, rw, a, Yw, rd, rsat,xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight)
HenXoma(1, 9.81, 0.017, 0, 8.8, 15.2, 1, 1, 0, 0, 2, 4, 0, 36.9, 15.2)
Sorry I mean global
Yw is used in several places in the code
and This is the places that Yw was used:
function HenXoma(flag, rw, a, Yw, rd, rsat,xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight)
global flag;
if (flag ==0 ||flag ==1)
dlor(rw, a, Yw, rd, rsat,xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight);
else if (flag ==2)
runtests (68.198, 0.5, 0.3, 0.2, 0.7, 1.2, 0.750821238038765, 1.077, 9.81, 0.00001, 8.8, 15.2, 2);
end
end
function dlor(rw, a, Yw, rd, rsat,xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight)
global rw a Yw rd rsat;
dlorg(xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight);
function [objP, padN, N] = plasticMultiplierTerms(nodes, discs, c, phiDegrees);
global flag;
global rw a Yw rd rsat;
objP = sparse(0, 0); padN = sparse(0, 0); N = sparse(0, 0); count = 1; tan_phi = tan(pi * phiDegrees / 180);
% [rw a Yw rd rsat]= deal(9.81, 0.017, 1, 8.8, 15.2);
for i = 1 : size(discs, 1)
if (discs(i, 3) < 2) % i.e. if rigid or symmetry
[eff_c eff_tanPhi] = deal(c * (discs(i, 3) ~= 1), tan_phi * (discs(i, 3) ~= 1));
[n1 n2 len] = deal(discs(i, 1), discs(i, 2), discs(i, 4));
if (flag == 1)
effc1 = eff_c;
eff_c = unsatCohesion(nodes(n1,2), nodes(n1, 3), nodes(n2,2), nodes(n2, 3), tan_phi, len, rw, a, Yw, rd, rsat);
[effc1 eff_c];
[i eff_c];
[con var] = deal(2 * count - 1, 2 * count - 1);
[con var];
N_local = [1 -1; eff_tanPhi eff_tanPhi];
N([con con + 1], [var var + 1]) = N_local;
N([con con + 1], [var var + 1]);
padN_local = sparse(2, 2 * size(discs, 1)); %All zero sparse: 2-by-12
[padN_local];
padN_local(1, 2 * i - 1) = -1;
padN_local(2, 2 * i) = -1;
padN = [padN; padN_local];
[padN];
objP = [objP eff_c * discs(i, 4) eff_c * discs(i, 4)];
[objP];
count = count + 1;
end
end
end
% SELF WEIGHT LOADS %
function swc = StripWeightChecking(a, rw, Yw, len, y1, y2, x1, x2, ymax, rsat, rd)
theta = atan2(y2-y1,x2-x1);
theta = abs(theta);
%theta = (theta*180/pi); Do not use this.It cause difference in results
if theta ~= 0 && theta ~= 90 && y1 >= Yw && y2 > Yw ; % above water table;
SW =(cos(theta)/(a*rw))*(((a*rw*rd*ymax)-((rsat-rd)*exp(a*rw*Yw)*exp((-1)*a*rw*ymax))-(a*rw*rd*y1))*len-(a*rw*rd*sin(theta)*(len^2/2))-((rsat-rd)*exp(a*rw*(Yw-y1))*exp((-1)*a*rw*len*sin(theta))/(sin(theta)*a*rw)) +(((rsat-rd)*exp(a*rw*(Yw-y1)))/(sin(theta)*a*rw))); % above water table
elseif theta ~= 0 && theta ~= 90 && y1 < Yw && y2 <= Yw && Yw == ymax; % under water table
SW = cos(theta)*((rsat*ymax*len)-(((len^2)/2)*rsat*sin(theta))-(rsat*y1*len)); % Sr=1 Yw= ymax
elseif theta ~= 0 && theta ~= 90 && y1 < Yw && y2 <= Yw && Yw < ymax; % under water table
SW = (rsat*Yw*len-(len^2/2)*rsat*sin(theta)-rsat*y1*len)*cos(theta)...
+ ((rd *ymax -((rsat-rd)/(a*rw))*exp(a*rw*(Yw-ymax))-rd*Yw +(rsat-rd)/(a*rw)))*(x2-x1); % Sr=1 Yw < ymax
elseif theta ~= 0 && theta ~= 90 && y1 < Yw && y2>Yw; %case in between
L1= abs((Yw-y1)* sin(theta)); % here I used abs values for L1 since all values of SINE are negative
L2 = abs((y2-Yw)*sin(theta)); % here I used abs values for L1 since all values of SINE are negative
SW = ((cos(theta))/(a*rw))*(((a*rw*rd*ymax)-((rsat-rd)*exp(a*rw*Yw)*exp((-1)*a*rw*ymax))-(a*rw*rd*Yw))*L2-(a*rw*rd*sin(theta)*(L2)^2/2)-((rsat-rd)*exp((-1)*a*rw*L2*sin(theta))/(sin(theta)*a*rw))+((rsat-rd)/(sin(theta)*a*rw)))...
+(rsat*ymax*L1-(L1^2/2)*rsat*sin(theta)-rsat*y1*L1)*cos(theta)...
+(1/(a*rw))*(((a*rw*rd*ymax)-((rsat-rd)*exp(a*rw*Yw)*exp((-1)*a*rw*ymax))-(a*rw*rd*Yw))+ (rsat-rd))*(L1*cos(theta)); %OKKKKKK
elseif x1 == x2;
SW = 0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if theta == 0 && y1 > Yw && y2 > Yw ; % above water table
SW = (rd*ymax - ((rsat-rd)*exp(a*rw*(Yw-ymax))/(a*rw))- rd*y1 + ((rsat-rd)*exp(a*rw*(Yw-y1))/(a*rw)))*(x2-x1); % above water table
elseif theta == 0 && y1 <= Yw && y2 <= Yw && Yw ==ymax; % under water table
SW =rsat*(ymax-y1)*(x2-x1); % Sr=1 Yw= ymax
elseif theta == 0 && y1 <= Yw && y2 <= Yw && Yw < ymax; % under water table
SW = rsat*(Yw-y1)*(x2-x1)+(rd*ymax-((rsat-rd)*exp(a*rw*(Yw-ymax))/(a*rw))-rd*Yw +((rsat-rd)/(a*rw)))*(x2-x1); % Sr=1 Yw <ymax
elseif x1 == x2;
SW = 0;
end
swc = SW;
function stripWeight = computeStripWeight(n1x, n1y, n2x, n2y, unitWeight, ymax, len, rw, a, Yw, rd, rsat);
global flag;
global rw a Yw rd rsat;
stripWidth = n2x - n1x;
stripWeight = unitWeight * stripWidth * (ymax - 0.5 * (n1y + n2y));
%stripWeight
% [rw a Yw rd rsat]= deal(9.81, 0.017, 1, 8.8, 15.2);
%[rw a Yw rd rsat]= deal(9.81, 0.017, 0, 8.8, 15.2);
stripWeight1 = StripWeightChecking (a, rw, Yw, len, n1y, n2y, n1x, n2x, ymax, rsat, rd);
%stripWeight1
[stripWeight stripWeight1];
if (stripWeight * stripWeight1 < 0)
fprintf('Warning - sign mismatch');
end
if (flag ==1)
stripWeight = stripWeight1;
end
function fD = selfWeight(nodes, discs, ymax, unitWeight);
fD = [];
for i = 1 : size(discs, 1)
[n1 n2 len] = deal(discs(i, 1), discs(i, 2), discs(i, 4));
[cosine sine] = deal((nodes(n1, 2) - nodes(n2, 2)) / len, (nodes(n1, 3) - nodes(n2, 3)) / len);
%i
stripWeight = computeStripWeight(nodes(n1,2), nodes(n1, 3), nodes(n2,2), nodes(n2, 3), unitWeight, ymax, len);
fD = [fD; -sine * stripWeight; -cosine * stripWeight];
[fD];
end
i will really appreciate your help
If it is necessary I will pot the entire code
Regards
Yw has no effect on your code if the global variable "flag" is 2. At present we have no way of knowing what its value is.
Bestun
Bestun 2012-4-18
Dear Walter
I am taking flag = 1 , so there is effect of Yw on the dlor function . Yes if flag = 2 , the code is running a test of the equations which are not depending on Yw value.
However, changing Yw from 0 to 1 does not change the solution (in my equations Yw is dependent variable) at all and it must be change
Regards

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by