- 65

- 0

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

E(:, :, j) = real( A(j, 1) .* exp (i.*(A(j, 2).*T - (A(j, 2) ./ c).*A(j, 3).*Z)));

end