Results 1 to 2 of 2

Math Help - Can someone please tell me my code wont work, error after error

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    17

    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
    Last edited by CaptainBlack; December 10th 2009 at 10:46 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by fearless901 View Post
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. The [5,2] error correcting code
    Posted in the Number Theory Forum
    Replies: 3
    Last Post: July 25th 2010, 08:03 AM
  2. error correcting code
    Posted in the Advanced Math Topics Forum
    Replies: 5
    Last Post: February 19th 2010, 02:37 AM
  3. Error Correcting Code
    Posted in the Advanced Math Topics Forum
    Replies: 0
    Last Post: January 25th 2010, 07:44 PM
  4. Replies: 0
    Last Post: April 1st 2009, 04:22 AM
  5. Error-correcting code proof
    Posted in the Discrete Math Forum
    Replies: 0
    Last Post: September 18th 2008, 10:21 PM

Search Tags


/mathhelpforum @mathhelpforum