What is the difference between int and integral.

83 visualizzazioni (ultimi 30 giorni)
Hello everyone
I want to get explained how to decide wheather use function "int" or "integral".
What is the basic difference between them? will they give same answer for a given function?
Thank you very much in advance.
  1 Commento
Ashwani Kumar MAlviya
Ashwani Kumar MAlviya il 9 Mag 2020
n = length(FC); % Calculates the Number of consistant respondents(Nt)
x = sum(FC == mode(FC)); % Calculates the Number of respondents answered mode
p = 1/17; % Probability of selecting mode(Pi)
mu = n*p;
sigma = sqrt(n.*p.*(1 - p)); % Standerd deviation
if n<= 20
i = 0;
syms i
alfa = double(symsum((factorial(n)/(factorial(i)*factorial(n-i))*(p).^(i)*(1-p).^(n-i)), i, 0, x)); % 0 = constant, 2 = x
% beta1 = symsum((factorial(n)/(factorial(i)*factorial(n-i))*(1-1/17).^(i)*(1/17).^(n-i)), i, 0, n-x);
% power = 1-beta1;
elseif n>20
syms y
f = (-(y-mu)^2)/(2*sigma^2); % 5.05 is 2*sigma^2, & 2.7 = mu
fun = (1/(sigma*2.5))*(exp(f)); % 0.2516 = 1/(sigma*2.5), e = 2.71
a = -inf;
b = x; %x; % number of respondent selected mode
alfa = double(int(fun, a, b));
%%% ^ if I am using integral here, I am getting different answer. what mistake am I making conceptually.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 9 Mag 2020
The int function integrates symbolic expressions (or does its best, consdidering that not all expressions have analytic integrals).
The integral function is for numeric functions, usually anonymous functions.
The documentation pages for those functions explain them better than I can, so I provided links to them.
  4 Commenti
Temi
Temi il 10 Dic 2022
Hello @Star Strider!!! when evaluating definite integrals using int, what integration scheme does the function use? trapezoid, rungekutta, quadrature, simpsons?
which is better to evaluate integrals numerically?; int or integral
Torsten
Torsten il 10 Dic 2022
Modificato: Torsten il 10 Dic 2022
"int" tries to find an analytical antiderivative of your function. So it does not use any numerical integration scheme.
For the integration method of "integral", see
[1] L.F. Shampine “Vectorized Adaptive Quadrature in MATLAB®,” Journal of Computational and Applied Mathematics, 211, 2008, pp.131–140.
If the function does not look too complicated, try "int" first.
If no analytical antiderivative can be found using "int", use "integral".

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by