Thursday, June 28, 2012

MATLAB - Vibration in a string (Hyperbolic Equation)


vibration_string
%************************ Vibration in stretched string ****************************
%******************************* By Mahesha MG *************************************
clc;
T= input('Tension on the string: ');
ro= input('Linear density of string: ');
l= input('Length of the string: ');
h= input('Step length: ');
tmax= input('Time: ');
tu=sqrt(ro*h^2/T);
x=0:h:l;
n=(l/h)+1;
m=ceil(tmax/tu);
f=zeros(m,n);
f(1,1)=input('Left boundary: ');
f(1,n)=input('Right boundary: ');
for i=2:m
    f(i,1)=f(1,1);      %Assigning the left boundary values
    f(i,n)=f(1,n);      %Assigning the right boundary values

end
for i=2:l/h
    f(1,i)=x(i)*(5-x(i)); %Initial condition
end
ft=zeros((l/h)+1,1);    %Initial condition
for i=2:n-1
    f(2,i)=0.5*(f(1,i+1)+f(1,i-1))+tu*ft(i);    %First time step

end
for i=2:m
    for j=2:1:n-1
        f(i+1,j)=f(i,j+1)+f(i,j-1)-f(i-1,j);
    end
end
ymax=max(max(f));
figure('color','white');

for i=1:m
    y=f(i,:);
   plot(x,y,'o');
   ylim([-ymax ymax]);
   title('Vibration in stretched string')
   xlabel('By: Mahesha MG maheshamg@gmail.com');
   getframe;
end

4 comments:

  1. Can you give an example of the usage?

    ReplyDelete
    Replies
    1. Hanging bridge is an example.
      Also it can be used to simulate vibration in any stretched string like strings in musical instruments.

      Delete
    2. What is meant by Step Size????

      Delete
    3. separation between two successive points. In numerical method, we are considering string as discrete points.

      Delete