How can I define square of a handle function inside an integral?
3 views (last 30 days)
Hello every body. This is my code and I get the error " Undefined function 'sqrt' for input arguments of type 'function_handle'."
kkk=@ (t) (sqrt((3.*a(1).*(t-tt(1)).^2+2.*b(1).*(t-tt(1))+c(1)).^2)).^3;
kk=@(t) (18*a(1).^2*(t-tt(1)).^2+2.*b(1).*6.*a(1).*6.*a(1).*b(1).*(t-tt(1)).^2 ...
John D'Errico on 1 Nov 2021
Edited: John D'Errico on 1 Nov 2021
kk is a function handle, as is kkk. (Really creative names there. Note that using better, more descriptive names will greatly improve your code in the future, when you need to debug that code. As well, don't reuse variables like that, where you create kk as a functino handle, and then immmediately try to create a new function handle with the same name. That will only bring you down into the depths of programming hell when you try to debud code like that.)
Anyway, you CANNOT do operations like this:
Instead, you need to create a new function handle derived from it. For example:
kkfun = @(t) sqrt(kk(t));
kfun = @(t) kkfun(t)./kkk(t);
The point is, you do not want to square the function handle itself, but to square what it does to the operand (t). You do not want to divide two function handles, one by the other, but to divide the result of those function handles.