Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Wave Equation - loop unrool in MATLAB?

  1. Apr 22, 2009 #1
    Hi,
    While trying to simulate wave a mixing scenario I wrote below.
    But it seems that matlab's matrix manipulation can easily unrol the marked loop (but i cannot find how). Can somebody help



    % speed of light
    c = 1;

    % matrix containing wave parameters in each row for number of waves
    % A = [w1; w2]
    % w1 = [Emax Freq IndexOfRefraction]
    % eg. below contains values for 2 waves
    % wave 1: Emax = 1, Freq = 15, IndexOfRefraction = 0.1

    A = [
    1 15 0.1 ;
    0.9 16 0.1
    ];


    z = linspace(0, 200, 2000);
    t = 0:.1:50;
    [Z, T] = meshgrid(z, t);
    waves = size(A, 1);
    dist = length(z);
    duration = length(t);
    E = zeros(duration, dist, waves);


    % Trying to unroll below?
    % E = E0*exp( i(wt - w/c*n*z))
    % E is a 3D matrix
    % rows contain values for each time interval
    % cols contain values for each distance (z)
    % pages contain values for each wave in A

    for j = 1:waves
    E(:, :, j) = real( A(j, 1) .* exp (i.*(A(j, 2).*T - (A(j, 2) ./ c).*A(j, 3).*Z)));
    end
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Wave Equation - loop unrool in MATLAB?
Loading...