MATLAB: Is this correct approach for a single summation in time domain

singe summationtime domain

Hey there,
I am trying to do a single summation of a function in the time domain. I got my code working, but I would feel more confident if someone would verify the correctness or point out my mistakes.
Here is also the formula for what I am trying to achieve:
Here is the code:
h = 100;
t=[1:400];
rho_w = 1025;
g = 9.81;
Ohm = [0.01:0.01:4]
Phase = rand(1,length(Ohm))*2*pi;
Amp = [1:1:400];
for i = 1:length(t)
P(i) = rho_w*g*sum(Amp.*Ohm.*cos(Ohm*t(i)+Phase))
end
Thanks a bunch!

Best Answer

Looks fine to me. I'll just point out that you could avoid the for-loop by doing
P = cos(bsxfun(@plus, t(:)*Ohm,Phase) )*(rho_w*g*Amp.*Ohm).';