Function with multiple equations? Getting Error "Not enough input arguments."

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 comentarios

VBBV
VBBV el 2 de Feb. de 2021
Editada: VBBV el 2 de Feb. de 2021
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
VBBV
VBBV el 2 de Feb. de 2021
Editada: VBBV el 2 de Feb. de 2021
If f is a vector, then first argument of besselk needs to be a vector of same size. It seems you have 0 as first argument
Not enough input arguments.
Error in my_bessel (line 11)
x =r*(sqrt(s(f).^2+s(f)*b)) ; % use the f as input data to compute x
This is the error I get if I run your version. Matlab asks me to have more inputs.
The first argument of besselk() defines the order of the function. I want that to be 0. Previously I've run this with no problems:
syms x X s f;
D = 10^(-6);
t = 10^(-9);
c = sqrt(D/t);
r = 10*10^(-6);
b = (1/(c*t));
f = linspace(0,1000,1001) ;
T = 10^(-5);
s = 2*(1i*pi*f) ;
x = r*(sqrt(s.^2+s*b)) ;
K_0 = besselk(0, x) ;
figure(1) ;
plot(f, K_0) ;
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.
I've been messing around with it for now and it seems to work (VBBV's version). I still get the same error but in another matlab script I can call the function and plot it. I just get warnings:
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Thanks for your time guys!
A hint: While 10^(-6) is an expensive power operation, 1e-6 is a cheap constant.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Feb. de 2021

Comentada:

Jan
el 3 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by