# Thread: Can someone please tell me my code wont work, error after error

1. ## Can someone please tell me my code wont work, error after error

im need to write code to get height and time of the fluid in a reservoir, help guys. is my functions wrong?

Code:
%  VALUES GIVEN AND ASSUMED
%DIMENSIONS AND OTHER CONSTANS
L=5;                                               %Length of Tube
x=0:.1:5;                                          %Length vector
dx=0.1;                                            %  FOR THE DISTANCE
Ao=1;                                              %Cross-Sectional Area of undeformed Tube
n=(L./dx)+1;                                       %number of nodes
Ro=10^3;                                           %Density of Fluid(Kg/m^3)
Co=10^3;                                           %propagation speed in an initially undeformed
kp=2/3*10^9;                                        %Tube law proportionality constant

% BOUNDARY CONDITIONS
u=zeros(1,n);                                       %Initializes velocity vector to zero
uo=-10;                                             %Velocity of withdrawn fluid(SET BY US)
u(1,1)=uo;                                          %Set the initial velocity to the velocity of withdrawn fluid
un=u;
t=0;                                               %Initializing t to zero
dt=0.00005;                                         %STEP SIZE FOR THE TIME
tmax=0.05;                                          %Total duration of simulation
A=ones(1,n);                                        %Initial Tube Area vector
An=A;                                               %INITIAL AREA

eval('A,kp,Ro,Ao,n');                              %calling evalc function
i_end=input('Enter 0 for open end  or 1 for closed end TUBE: ');
ip=input('Enter 0 for A vs x or 1 for u vs x: ');     %  Graphic preference

GRAPHICS(x,A,u,ip,t)                                 %calling graphics function

while t<tmax
%clearing variables

Co=Cn;
uo=un;
Ao=An;
DUA=0;
Cn=c;

while 1

B=zeros((2.*n),1);
M=zeros((2.*n),4);

sol=zeros(1,(2.*n));

[M,B]=setUA(dx,dt,n,i_end,Co,Ao,Cn,un,An)

dUA=solveUA(M,B)
for i=1:n

dU=dUA(i,2*i+1);
dA=dUA(i,2*i);
un=uo+dU;
An=Ao+dA;

end

c=evalc(An,kp,Ro,Ao);
if max(abs(dUA-DUA))<5*10^-6,break,end
DUA=dUA;
end
t=t+dt;
i_end=input('Enter 0 for open end scenario or 1 for closed end scenario: ');
ip=input('Enter 0 for A vs x or 1 for U vs x: ');
GRPHCS(x,A,U,ip,t)
end

2. Originally Posted by fearless901
im need to write code to get height and time of the fluid in a reservoir, help guys. is my functions wrong?

Code:
%  VALUES GIVEN AND ASSUMED
%DIMENSIONS AND OTHER CONSTANS
L=5;                                               %Length of Tube
x=0:.1:5;                                          %Length vector
dx=0.1;                                            %  FOR THE DISTANCE
Ao=1;                                              %Cross-Sectional Area of undeformed Tube
n=(L./dx)+1;                                       %number of nodes
Ro=10^3;                                           %Density of Fluid(Kg/m^3)
Co=10^3;                                           %propagation speed in an initially undeformed
kp=2/3*10^9;                                        %Tube law proportionality constant

% BOUNDARY CONDITIONS
u=zeros(1,n);                                       %Initializes velocity vector to zero
uo=-10;                                             %Velocity of withdrawn fluid(SET BY US)
u(1,1)=uo;                                          %Set the initial velocity to the velocity of withdrawn fluid
un=u;
t=0;                                               %Initializing t to zero
dt=0.00005;                                         %STEP SIZE FOR THE TIME
tmax=0.05;                                          %Total duration of simulation
A=ones(1,n);                                        %Initial Tube Area vector
An=A;                                               %INITIAL AREA

eval('A,kp,Ro,Ao,n');                              %calling evalc function
i_end=input('Enter 0 for open end  or 1 for closed end TUBE: ');
ip=input('Enter 0 for A vs x or 1 for u vs x: ');     %  Graphic preference

GRAPHICS(x,A,u,ip,t)                                 %calling graphics function

while t<tmax
%clearing variables

Co=Cn;
uo=un;
Ao=An;
DUA=0;
Cn=c;

while 1

B=zeros((2.*n),1);
M=zeros((2.*n),4);

sol=zeros(1,(2.*n));

[M,B]=setUA(dx,dt,n,i_end,Co,Ao,Cn,un,An)

dUA=solveUA(M,B)
for i=1:n

dU=dUA(i,2*i+1);
dA=dUA(i,2*i);
un=uo+dU;
An=Ao+dA;

end

c=evalc(An,kp,Ro,Ao);
if max(abs(dUA-DUA))<5*10^-6,break,end
DUA=dUA;
end
t=t+dt;
i_end=input('Enter 0 for open end scenario or 1 for closed end scenario: ');
ip=input('Enter 0 for A vs x or 1 for U vs x: ');
GRPHCS(x,A,U,ip,t)
end
Tell us what the first error message is, or better yet just tell us all of them.

Also, what do you think this line does:

eval('A,kp,Ro,Ao,n'); %calling evalc function

And:

Consider single stepping through the code in the debugger.

CB