MATLAB Wave Equation - loop unrool in MATLAB?

  • Thread starter krindik
  • Start date
65
0
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
 

Want to reply to this thread?

"Wave Equation - loop unrool in MATLAB?" You must log in or register to reply here.

Related Threads for: Wave Equation - loop unrool in MATLAB?

Replies
0
Views
2K
  • Posted
Replies
0
Views
5K
Replies
0
Views
994
Replies
0
Views
2K
Replies
0
Views
1K
  • Posted
Replies
0
Views
2K
Replies
0
Views
5K
Replies
0
Views
6K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top