Not Enough Input Arguments

Hi,
I have a formula that includes two variables T and d but whatever i try matlab gives an error saying that that T and d might be unused. I have 7 different T and d values and have to calculate 7 different output from function using matched T and d values. How can i define T and d as an input?
Here is my code without inputs,
function L=dispersion(T,d)
L=9.81*T*T/(2*pi);
Lo=0;
while abs(L-Lo)>10^-8;
Lo=L;
L=(9.81*T.^2./(2*pi))*(tanh(2*pi*d/L));
end
end

2 Comments

You need to have some formula for T and d. You need to predefine (user input or some variable or some formula) T and d.
dj
dj on 17 Oct 2018
Well thats my problem exactly. I just have T and d values not their formula. Like; T=0.5 0.5 1 1 5 5 10 d=0.1 0.1 0.5 0.5 5 10 50
How can i predefine T and d variables for my code?

Answers (1)

Jan
Jan on 18 Oct 2018
T = [0.5 0.5 1 1 5 5 10];
d = [0.1 0.1 0.5 0.5 5 10 50];
L = dispersion(T,d)
function L = dispersion(T,d)
L = 9.81 * T .^ 2 / (2*pi);
Lo=0;
while any(abs(L-Lo) > 1e-8)
Lo = L;
L = (9.81 * T.^2 ./ (2*pi)) .* tanh(2 * pi* d ./ L);
end
end
Using the iteration for all different T values might be inefficient. I would call the function in a for loop instead.

This question is closed.

Tags

Asked:

dj
on 17 Oct 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!