MATLAB Hydraulic Circuit Losses
clc
clear
M=10;
D(1:M)=[0.5];
a=0.5*(16/(pi)^2);
L=[0 4 2 4 2 4 8 2 2 0 ];
f=[0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005];
r(1:M+1)=1.23;
Q(1)=1;
Q(2)=0.5;
Q(3)=0.5;
Q(4)=0.5;
Q(5)=0.5;
Q(6)=0.5;
Q(7)=0.5;
Q(8)=Q(5);
Q(9)=Q(3);
Q(10)=Q(9)+Q(2);
for i=1:M;
A(i)=0.25*pi*D(i)^2;
v(i)=Q(i)/A(i);
end
for i=1:M;
dp(i)=a*(1/(D(i)^5))*L(i)*f(i)*r(i)*(Q(i))^2;
end
Flow1_Res= Q(1)-Q(2)-Q(3)
Sq_Flow1_Res=(Flow1_Res)^2
Flow2_Res= Q(3)-Q(4)-Q(5)
Sq_Flow2_Res=(Flow2_Res)^2
Flow3_Res= Q(5)-Q(6)-Q(7)
Sq_Flow3_Res=(Flow3_Res)^2
Head1=dp(3)+dp(9)+dp(4)-dp(2)
Sq_Head1_Res=(Head1)^2
Head2=dp(5)+dp(8)+dp(6)-dp(4)
Sq_Head2_Res=(Head2)^2
Head3=dp(7)-dp(6)
Sq_Head3_Res=(Head3)^2
Target=Sq_Flow1_Res+Sq_Flow2_Res+Sq_Flow3_Res+Sq_Head1_Res+Sq_Head2_Res+Sq_Head3_Res
clear
M=10;
D(1:M)=[0.5];
a=0.5*(16/(pi)^2);
L=[0 4 2 4 2 4 8 2 2 0 ];
f=[0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005];
r(1:M+1)=1.23;
Q(1)=1;
Q(2)=0.5;
Q(3)=0.5;
Q(4)=0.5;
Q(5)=0.5;
Q(6)=0.5;
Q(7)=0.5;
Q(8)=Q(5);
Q(9)=Q(3);
Q(10)=Q(9)+Q(2);
for i=1:M;
A(i)=0.25*pi*D(i)^2;
v(i)=Q(i)/A(i);
end
for i=1:M;
dp(i)=a*(1/(D(i)^5))*L(i)*f(i)*r(i)*(Q(i))^2;
end
Flow1_Res= Q(1)-Q(2)-Q(3)
Sq_Flow1_Res=(Flow1_Res)^2
Flow2_Res= Q(3)-Q(4)-Q(5)
Sq_Flow2_Res=(Flow2_Res)^2
Flow3_Res= Q(5)-Q(6)-Q(7)
Sq_Flow3_Res=(Flow3_Res)^2
Head1=dp(3)+dp(9)+dp(4)-dp(2)
Sq_Head1_Res=(Head1)^2
Head2=dp(5)+dp(8)+dp(6)-dp(4)
Sq_Head2_Res=(Head2)^2
Head3=dp(7)-dp(6)
Sq_Head3_Res=(Head3)^2
Target=Sq_Flow1_Res+Sq_Flow2_Res+Sq_Flow3_Res+Sq_Head1_Res+Sq_Head2_Res+Sq_Head3_Res
Applying the Iterations Section is Very Similar to the Following Code
clc
clear
we=0.99;
it=25
A=[2 1; 5 7]
b=[11 13]
x(1:2,1)=[500 500]
D = diag(A,0)
D_1=[1/D(1,1) 0; 0 1/D(2,1)]
L=tril(A,-1)
U=triu(A,+1)
T=D_1*(-L-U)
C=D_1*b.'
x(1:2,2)=we*T*x+(1-we)*C;
x(1:2,2)
for i=1:it;
x(1:2,i+1)=we*T*x(1:2,i)+(1-we)*C
end
figure(1)
for i=1:it;
plot(x(1,1:i),'r-*')
hold on
end
%axis equal
xlabel('Number of Iterations')
ylabel('Calculated Value')
grid on
hold off
figure(2)
for i=1:it;
plot(x(2,1:i),'b-*')
hold on
end
%axis equal
xlabel('Number of Iterations')
ylabel('Calculated Value')
grid on
clear
we=0.99;
it=25
A=[2 1; 5 7]
b=[11 13]
x(1:2,1)=[500 500]
D = diag(A,0)
D_1=[1/D(1,1) 0; 0 1/D(2,1)]
L=tril(A,-1)
U=triu(A,+1)
T=D_1*(-L-U)
C=D_1*b.'
x(1:2,2)=we*T*x+(1-we)*C;
x(1:2,2)
for i=1:it;
x(1:2,i+1)=we*T*x(1:2,i)+(1-we)*C
end
figure(1)
for i=1:it;
plot(x(1,1:i),'r-*')
hold on
end
%axis equal
xlabel('Number of Iterations')
ylabel('Calculated Value')
grid on
hold off
figure(2)
for i=1:it;
plot(x(2,1:i),'b-*')
hold on
end
%axis equal
xlabel('Number of Iterations')
ylabel('Calculated Value')
grid on
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com