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

 採用された回答

Geoff Hayes
Geoff Hayes 2020 年 5 月 11 日

0 投票

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 件のコメント

Juan Sebastián Delgado Burgos
Juan Sebastián Delgado Burgos 2020 年 5 月 11 日
OMG, it worked, thank you very much!
i will take into account the "@" and the ".*" since now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by