Using the right values for the variables, function gives a completely wrong answer
Show older comments
Hello,
I'm afraid of this being a rather simple solution, but I am out of ideas here.. I've been setting up a calcuation in matlab, and I spotted a function giving a completely wrong answer despite of all variables being correct:
clear all; close all;
%%
% Constants used for this calculation
g=9.81; % [m/s2] gravitational constant
rho_w=1000; % [kg/m3] water density
nu=10^-6; % [m2/s] water kinematic viscosity
k=0.4; % [-] Von Karman constant
% Additionally considering the following:
T=6; % [s] wave period
H=1.2; % [m] wave height
D=20; % [m] water depth
%% Problem 2.1
% Calculating wavenumber, wavelength, and celerity at this depth:
syms k
omega = 2*pi/T
Linear = omega^2 == g*k*tanh(k*D)
k_initial = omega^2/g % using deep water wave number was an initial condition
sol_k=vpasolve(Linear,k,k_initial)
L=2*pi/sol_k
My issue is specifically with the very last line here. When checking each variable up to that point one by one, it is clear that pi=3.1416, sol_k=0.1141369, which should give 2*3.1416/0.1141369=55.05. Instead matlab is telling me it's 17.523.
I've been sitting here for some time and I am confused on how this can even be possible here, considering it is a simple division.
1 Comment
Stephen23
on 3 Dec 2022
"Instead matlab is telling me it's 17.523. "
No, MATLAB is telling you that it is 17.523* pi:
If you want a purely numeric value without pi, then use DOUBLE(L)
Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!