Results 1 to 3 of 3

Math Help - matlab - defining boundaries

  1. #1
    Newbie
    Joined
    Oct 2009
    Posts
    24

    matlab - defining boundaries

    Hi
    I'm writing a script in matlab to simulate waves in a string such that "For this example, we assume a string of length 100 cm and a step size in x (along the string) of 1 cm. We shall assume a wave velocity of 1 cm/sec. You will write your program so that it computes the propogation of waves along the string for 200 seconds"
    and
    "for boundary conditions we will assume a triangular displacement with height of 1 cm located more or less in the center of the string. The slope of the sides of the triangle is .25 cm per cm"
    You can see how this is illustrated here:
    Slide 1
    What I *want* to do is:
    V(1,j) = 0.00;
    V(2,j) = 0.25;
    V(3,j) = 0.50;
    V(4,j) = 0.75;
    V(5,j) = 1.00;
    although this isnt working.
    My program looks like this:

    Code:
    % Julie Miller
    % Exercise 17
    
    
    dx = 1.0;
    x = 0:dx:100.0;
    dt = input('enter time step(s):  ');
    t = 0:dt:200.0;
    
    tlength = (200/dt)+1;
    xlength = (100/dx)+1;
    
    V = zeros(xlength,tlength);
    V(1,j) = 0.00;
    V(2,j) = 0.25;
    V(3,j) = 0.50;
    V(4,j) = 0.75;
    V(5,j) = 1.00;
    
    alpha = (dt^2)/(dx^2);
    while alpha < 1.0;
        for i = 2:xlength-1
       V(i,2) = (alpha/2)*(V(i-1,1)+V(i+1,1))+(1-alpha)*(V(i,1));
        end
    for j = 2:tlength-1
         for i = 2:xlength-1
            V(i,j+1) = alpha*(V(i-1,j)+V(i+1,j))+2*(1-alpha)*(V(i,j)-V(i,j-1));
         end
    end
    end
    
        
    mesh(V)
    ....how do I get this slope of 25 cm / cm? Thanks very much
    Last edited by CaptainBlack; December 15th 2009 at 02:18 AM.
    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 plopony View Post
    Code:
    % Julie Miller
    % Exercise 17
     
     
    dx = 1.0;
    x = 0:dx:100.0;
    dt = input('enter time step(s):  ');
    t = 0:dt:200.0;
     
    tlength = (200/dt)+1;
    xlength = (100/dx)+1;
     
    V = zeros(xlength,tlength);
    V(1,j) = 0.00;
    V(2,j) = 0.25;  
    V(3,j) = 0.50;
    V(4,j) = 0.75;
    V(5,j) = 1.00;
     
    alpha = (dt^2)/(dx^2);
    while alpha < 1.0;
        for i = 2:xlength-1
           V(i,2) = (alpha/2)*(V(i-1,1)+V(i+1,1))+(1-alpha)*(V(i,1));
        end
       for j = 2:tlength-1
         for i = 2:xlength-1
            V(i,j+1) = alpha*(V(i-1,j)+V(i+1,j))+2*(1-alpha)*(V(i,j)-V(i,j-1));
         end
       end
    end 
     
    mesh(V)
    What does the code in red above do? What value of j is it going to use?

    Code in blue is an infinite loop or does nothing.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Oct 2009
    Posts
    24
    the red code i know is incorrect. that is just me trying to take a stab at defining a boundary.

    in the blue code, i've been instructed to take out the while loop. i was trying to set the condition that there is only stability if alpha < 1.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Relationship of Boundaries
    Posted in the Differential Geometry Forum
    Replies: 3
    Last Post: July 13th 2011, 12:56 AM
  2. PDE with moving boundaries
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: May 4th 2011, 10:40 AM
  3. Boundaries
    Posted in the Math Topics Forum
    Replies: 10
    Last Post: January 8th 2011, 01:27 PM
  4. Need help with the boundaries of a 3D solid
    Posted in the Calculus Forum
    Replies: 2
    Last Post: February 13th 2010, 01:46 PM
  5. Polar Boundaries.
    Posted in the Calculus Forum
    Replies: 6
    Last Post: October 20th 2009, 04:13 AM

Search Tags


/mathhelpforum @mathhelpforum