Hi,(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Wave Equation - loop unrool in MATLAB?

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - Wave Equation loop | Date |
---|---|

Matlab Coding angular spectrum of waves in a fluid | Thursday at 7:30 AM |

Wave Packet Graph in GLE | Sep 9, 2016 |

Series of Standing Waves in Matlab | May 17, 2015 |

Help please in matlab -- plotting a D'Alembert wave equation | Jan 6, 2015 |

Simulating Schrodinger wave equation using MATLAB. | Aug 20, 2010 |

**Physics Forums - The Fusion of Science and Community**