MATLAB: Problems with integers help

integers

Hi guys, i've got a problem with an integer i need to do
my code:
function [y]= fun(x)
y= (34/(x*pi))*sin(x*pi/6)*exp((-x^2)*(pi^2)*(2.9652/54));
end
and i'm trying
q= integral(fun,1,inf)
it doesn't work, don't know why

Best Answer

Juan - please clarify what you mean by it doesn't work. Are there errors? If so, what are they? When I run your code (as is) I see a
Error using xx>fun (line 10)
Not enough input arguments.
because the code is trying to call fun when you are passing it into the integral function. You need to indicate that you are passing in a handle to the function instead. So just do
q= integral(@fun,1,inf) % <---- use the @ to denote a function handle
When this has been fixed, then the next error is
Error using /
Matrix dimensions must agree.
Since the x input paramter to this function fun will be an array, you will need to do element-wise operations in your code
function [y]= fun(x)
y= (34./(x*pi)).*sin(x*pi/6).*exp((-x.^2).*(pi^2)*(2.9652/54));
This will produce an answer...perhaps even the correct one! :)