# Why do I only have an output of zeros for the 1 X 800

1 view (last 30 days)
Agnella Dougal on 20 Oct 2020
Edited: Matt J on 20 Oct 2020
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
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.

Matt J on 20 Oct 2020
Edited: Matt J on 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.

Agnella Dougal on 20 Oct 2020
okay thank you
Agnella Dougal on 20 Oct 2020
Kr are all zeros do you Know how I can fix this
Matt J on 20 Oct 2020
Is it obviously wrong that Kr are all zeros? In any case, since Kr is generated by the refra() function, whatever that is, you should check to see if refra() is working properly.