Problems with integers help

6 views (last 30 days)
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

Accepted Answer

Geoff Hayes
Geoff Hayes on 11 May 2020
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! :)
  1 Comment
Juan Sebastián Delgado Burgos
OMG, it worked, thank you very much!
i will take into account the "@" and the ".*" since now.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!