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

 采纳的回答

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 个评论

OMG, it worked, thank you very much!
i will take into account the "@" and the ".*" since now.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by