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

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 11 Mai 2020

0 votes

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 commentaire

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

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by