How do I perform several iterations in MATLAB?
Ältere Kommentare anzeigen
I am trying to find the corresponding wave length from about 8,000 wave period data points. I have the matlab code to import the data and turn it into a table. I need to use each individual wave period and run iterations to find wave length using this equation: L = 1.56(T^2)tanh(61.58/L). I am not sure where to start, this is all I have so far.
%% Create Table From Excel File
% Identify excel file
filename = '2022WaveData.xlsx'; % Excel File Name
sheet = 1; % Sheet number
% Import data from the Excel file
wavedata = readtable(filename);
% Select every 2nd cell from the data - create array of hourly data
hourlydata = wavedata(1:2:end, :);
% Use only two columns from the selected data
hourlydata = hourlydata(:, 9:10); % Isolate wave height and dominant wave period
% Display the selected data
disp('Hourly Wave Data 2022:');
disp(hourlydata);
%% Perform an iterative calculation to find wavelength
% L = 1.56*(y^2)*tanh(61.58/L)
% Initial guess for L
L = 60;
% Perform the iterative calculation
y = hourlydata(:, 2);
for K = 1 : 100
L = 1.56*(y^2)*tanh(61.58/L);
end
% Display the final value of L
disp(['The wavelength [m] is approximately: ', num2str(L)]);
Any help would be greatly appreciated!
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 9 Nov. 2023
Change
for K = 1 : 100
L = 1.56*(y^2)*tanh(61.58/L);
end
to
LGuess = 60;
for K = 1 : 100
L(K) = fzero(@(L) 1.56*(y(K)^2)*tanh(61.58/L) - L, LGuess);
end
This presumes that L = 1.56*(y^2)*tanh(61.58/L) is an equation to be solved for L given a particular y value.
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!