Why do I only have an output of zeros for the 1 X 800
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I have this code that I developed for the function Kr_eff to get the output of five different coefficient values, but I only get zeros:
Here is my function:
function [Kr_eff] = refra_eff(Hs,fp,smax,alpha_po,d)
%--------------------------------------------------------------------------
% function Kr_eff = refra_eff(Hs,fp,smax,alpha_po,d)
% To calculate Kr Input
% Hs = significant water wave height
% fp = peak frequency array in Hz.
% smax = swell with short decay distance: (with relatively large wave steepness)
% alpha_po = angle array in degrees
% d = water depth
% Output
% Kr = refraction coefficient
%--------------------------------------------------------------------------
%alpha_po = alpha_po * pi / 180; % from degree to radian
Tp = 1/fp % peak period
Ts = Tp/1.05 % significant wave period
g = 9.81 % gravity
Lo = (g*(Ts^2))/(2*pi) % initial deep water wave length
% to obtain thetadeg use directional spectrum function
[S,thetadeg,f] = directional_wave_spec(Hs,fp,smax)
theta = thetadeg*pi/180; % degrees to radians
B = zeros(1,800)
Alpha_po = [alpha_po theta]
C = zeros(1,1)
Theta = [theta C]
% loop for theta 1 to 180 degrees which would be pi in radians
alpha_o = Alpha_po + (Theta./2)
[Kr,alpha] = refra(d,Ts,alpha_o)
L = ldis(d,Ts) % linear dispersion computes wavelength
Ks = shoal(d,Ts) % shoaling coefficient
mso = sum(S.*(Ks^2))
Kr_eff = ((1./mso).*sum(S.*(Ks.^2).*(Kr.^2)))
%alpha = alpha * 180 / pi; % from radian to degree
And here is the script when I test out my function:
% Nella HW 3
% Testing Kr_eff Script
clc, clear
Hs = 1; % significant wave height meters
fp = 0.1; % peak frequency
g = 9.81; % gravity
smax = 25; % swell with short decay distance: (with relatively large wave steepness)
d = 20 % from 0 to an infinite depth in meters
Tp = 1/fp % peak period
Ts = Tp/1.05 % significant wave period
g = 9.81 % gravity
Lo = (g*(Ts^2))/(2*pi) % initial deep water wave length
alpha_po1 = 0
Kr_eff1 = refra_eff(Hs,fp,smax,alpha_po1,d)
alpha_po2 = 20
Kr_eff2 = refra_eff(Hs,fp,smax,alpha_po2,d)
alpha_po3 = 30
Kr_eff3 = refra_eff(Hs,fp,smax,alpha_po3,d)
alpha_po4 = 40
Kr_eff4 = refra_eff(Hs,fp,smax,alpha_po4,d)
I then want to plot these values of Kr_eff in a plot, but they only are zeros, please help.
0 commentaires
Réponses (1)
Matt J
le 20 Oct 2020
Modifié(e) : Matt J
le 20 Oct 2020
We cannot run your code, but a good debugging strategy would be to pause execution at this line,
Kr_eff = ((1./mso).*sum(S.*(Ks.^2).*(Kr.^2)))
and examine the contents of mso and Kr as described here:
My bet is that all your Kr(i) values are zero.
3 commentaires
Voir également
Catégories
En savoir plus sur Signal Generation and Preprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!