Hello everyone,
I am trying to generate velocity from JONSWAP spectrum.However, when the depth of is higher than 20 m, MATLAB does not plot anything
I did not succeed to figure out the problem. The code is the following:
x=0;
depth=50;
mean_wind_speed=11.5;
gamma_jonswap=3.3;
f_p=0.208;
Tp=1/f_p;
t=linspace(0,1000,5000);
fs=length(t)/t(end);
delta_f=fs/length(t); % frequency step
g=9.81; % gravity
f=linspace(1e-3,(fs-delta_f)/2,length(t));
fetch=40e+3;
alpha_p=0.076*(fetch*g/(mean_wind_speed)^2)^(-0.22);
k=(2*pi*f).^2/g; % wave number
sigma_jonswap=zeros(1,length(f));
for j=1:length(f)
if f(j)<=f_p
sigma_jonswap(j)=0.07;
else
sigma_jonswap(j)=0.09;
end
end
pm_spectrum= alpha_p*g^2*(2*pi)^(-4).*f.^(-5).*exp(-(5/4)*(f_p./f).^4);
jonswap_spectrum=pm_spectrum.*gamma_jonswap.^exp(-((f-f_p*ones(1,length(f))).^2)./((2*sigma_jonswap.^2).*((f_p*ones(1,length(f))).^2)));
a=sqrt(2*jonswap_spectrum*delta_f);
phi=2*pi*rand(1,length(a));
%% velocity from JONSWAP spectrum
velocity_jonswap=zeros(1,length(t));
for j=1:length(t)
velocity_jonswap(j)=sum(2*pi*f.*(cosh(k*(depth))./(Tp*sinh(k*depth))).*a.*sin(k*x-2*pi*f*t(j)+phi));
end
figure(1)
plot(t,velocity_jonswap)
xlabel('time(s)')
ylabel('velocity of the wave')
title('velocity of the wave generated using JONSWAP spectrum at z=0 and x=0')
grid on
Could anyone help ?
Best Regards

 채택된 답변

Star Strider
Star Strider 2023년 2월 22일
이동: Walter Roberson 2023년 2월 22일

0 개 추천

The problem is that ‘velocity_jonswap’ is uniformaly NaN. This is causec by a ‘0/0’ , ‘Inf/Inf’ or NaN values in the data used to calculate that variable (that are caused by the same sorts of divisions). You will need to search to find out where the problem is, and then correct it.

댓글 수: 3

nado
nado 2023년 2월 22일
이동: Walter Roberson 2023년 2월 22일
Thanks a lot !
The problem was the input to cosh and sinh which was too large, that's why velocity_jonswap was giving NaN
Star Strider
Star Strider 2023년 2월 22일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
Walter — Thank you!
.
Walter Roberson
Walter Roberson 2023년 2월 22일
I can allieviate the input-too-large problem by switching to symbolic work, as the cosh() and sinh() cancel each other out to reasonable degrees. However, the resulting code is pretty slow in calculating velocity_jonswap because it is using 5000 different frequencies (length(t) of them.)
It is not immediately obvious to me why the number of frequencies should be the same as the number of time points. If you had used half as many frequencies as time points then I might have said, "Oh, that's sort of fourier transform kind of thing, going up to the nyquist frequency."

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2023년 2월 22일

댓글:

2023년 2월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by