compute numerical integral by matlab

Hello everybody Please,I want to know,how compute integral from 2 to infinity for any function using matlab? thanks in advance

 Risposta accettata

Matt Fig
Matt Fig il 7 Apr 2011

1 voto

Put the function in an anonymous function, then use QUADGK.

3 Commenti

reem
reem il 7 Apr 2011
Thank you so much Matt
but when I wany to run the function,some error occur
how can I solve it?
function y = myfun(X)
y=(1/sqrt(2*pi))*exp(-0.5*X^2);
Q=quadgk(@myfun,2,inf)
display(Q)
end
??? function y = myfun(X)
|
Error: Function definitions are not permitted at the prompt or in
scripts.
Don't put the keyword: function in a script or at the command line. Just do this:
y=@(X)(1/sqrt(2*pi))*exp(-0.5*X.^2); % Anonymous func.
Q=quadgk(y,2,inf)
reem
reem il 7 Apr 2011
Thank you so so so much
you are very kind and smart
I hope all best things for you
Kind regards

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by