

%                        Program trans(mission)
%
%    This program solves the transmission problem of two strings joined
%    at the origin. The speed of propagation on the right is set to 1.
%    User must enter the value "cl" of the speed on the left.
%       The  program solves two problems. In the first case a wave G(x+t)
%    is incident from the right. The function G(x) is provided in the
%    mfile bigg.m.  Use the second data choice in the file bigg.m. The program
%    calculates and plots snapshots of the solution at times t0 = 0,t1,t2.
%    The snapshots are plotted on [-10, 10].
%       The  second problem involves a sinusoidal wave incident from
%    the right of frequency omega and wave number k_right. Because
%    c_right = 1, omega = k_right.  User enters frequency omega and
%    the speed of propagation cl.  The program calculates the wave
%    number k_left, and the amplitude A of the transmitted wave.
%    The spatial factor of the solution is plotted on [-10, 10].



cl = input(' enter the value of cleft   ')

m = input(' Enter 1 for problem 1,  2 for problem 2  ')

if m == 1 

   refl = (cl-1)/(cl+1);
   tr = 2*cl/(1+cl);
 
   fprintf(' Reflection Coefficient is %g.\n', refl )
   fprintf(' Transmission Coefficient is %g\n', tr )

   t = input('Enter the times in the form [t1,t2]      ')

   t1 = t(1); t2 = t(2); 

   x = -10:.1:10;



%normalizing factor so that incident wave has height 1.

   r = 1.3146;

   snap0 = r*bigg(x);

   u = tr*bigg((x+cl*t1)/cl)*r;
   uleft = u(1:100);
   v = r*bigg(x+t1) + refl*r*bigg(t1-x);
   vright = v(101:201);
   snap1 = [uleft, vright];

   u = tr*bigg((x+cl*t2)/cl)*r;
   uleft = u(1:100);
   v = r*bigg(x+t2) + refl*r*bigg(t2-x);
   vright = v(101:201);
   snap2 = [uleft, vright];

    M0 = max(snap0);
    M1 = max(snap1);
    M2 = max(snap2);

    M = max([M0, M1, M2])

   subplot(3,1,1)
     plot(x, snap0)
     axis([-10 10 -M M])
   subplot(3,1,2)
     plot(x, snap1)
     axis([-10 10 -M M])
   subplot(3,1,3)
     plot(x,snap2)
     axis([-10 10 -M M])

else

   omega = input('Enter the frequency omega    ')

   kl = omega/cl;
   kr = omega;

   x = -10: .1 : 10;
   v = (x< 0)*cl.*sin(kl*x) + (x > 0).*sin(kr*x);
   plot(x, v)
end



