Function with multiple equations? Getting Error "Not enough input arguments."
Show older comments
Hello,
I'm trying to create a function that uses the matlab function besselk(nu,z) (Modified Bessel function of the second kind K_0). It should be something like this: K_(r*(sqrt(s^2+s*b))), with s being a Laplace variable. There is somehting wrong in my code, I get the error Not enough input arguments (but i only want one input for this function):
function [K] = my_bessel(f)
D = 10^(-6);
t = 10^(-9);
c = sqrt(D/t);
r = 10*10^(-6);
b = (1/(c*t));
T = 10^(-5);
s = 2*(1i*pi*f) ;
x = r*(sqrt(s.^2+s*b)) ;
K = besselk(0,x) ;
end
To fix this I've tried:
s =@(f) 2*(1i*pi*f) ;
x =@(f) r*(sqrt(s.^2+s*b)) ;
K =@(f) besselk(0,x) ;
This doesn't give me any errors straight away but the function doesn't seem to work when I call for it.
Side note: the reason I'm doing this is K_0(r*(sqrt(s.^2+s*b))) is a transfer function that I'm trying to implement in FPGA. My goal is to do a lookup table approximation of the function because doing the classical bilinear transformation won't work unless the transfer function is a polynomial. I've tried approximating the function to a polynomial. I used taylor and Newton's binomial theorem to approximate it by hand, but only til the second degree. This was not accurate. Maybe someone may have tips for approximating exp(-x) and sqrt() functions on matlab without creating a mega long polynomial?
Anything can help.
Thanks
6 Comments
s =@(f) 2*(1i*pi*f) ;
x =r*(sqrt(s(f).^2+s(f)*b)) ; % use the f as input data to compute x
K = besselk(0,x) ;
Note that besselk function has second argument as vector of inputs,
In your case 2nd line returns a function handle, which goas as 2nd argument to the function besselk. so You can define in f
Matis Tartie
on 3 Feb 2021
Walter Roberson
on 3 Feb 2021
The error you are getting is what would be expected if you invoked my_bessel without any arguments, or if you invoked it with f being a function handle that needs at least one parameter.
Matis Tartie
on 3 Feb 2021
Jan
on 3 Feb 2021
A hint: While 10^(-6) is an expensive power operation, 1e-6 is a cheap constant.
Answers (0)
Categories
Find more on Mathematics 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!