Integral of two variables divergent function
Afficher commentaires plus anciens
I am new to matlab and I am trying to understand how it works. I managed to integrate some functions of two variables that could diverge
eps=1/100;
A=5;
B=6;
x0=11/2;
for i=1:100000;
passo(i)= i/1000;
end
cts=@(x)coth(pi*(x)/10)/10;
deltaS=(B-A)/10;
for i=1:100000;
deltaS(i)=integral(@(x)exp(-((passo(i)-x-x0).^2)), A, B);
if(passo(i)<(A-eps))
ctqST(i)=-integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, passo(i)-A);
elseif(passo(i)>(B+eps))
ctqST(i)=-integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, passo(i)-A);
elseif(passo(i)<(B-eps)&passo(i)>(A+eps))
ctqS1= -integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), eps, passo(i)-A);
ctqS2= -integral(@(x)exp(-((passo(i)-x-x0).^2)).*cts(x), passo(i)-B, -eps);
ctqST(i)=ctqS2+ctqS1;
else
ctqST(i)=0;
end
risultato(i)=1-deltaS(i)+ctqST(i);
end
Now I have to integrate something that seems simpler,
cts=@(x)tanh(pi*(x)/10)*(sqrt(5)*0.8526)/(20*2*10);
for i=1:1000;
passo(i)= i/100-0.1;
end
eps=1/100;
A=-1;
B=10;
deltaS=(B-A)/10;
for i=1:1000;
deltaS(i)=integral(@(x)(passo(i)-x).^(-3/8), -Inf, Inf);
ctqST(i)=-integral(@(x)cts(x).*((passo(i)-x).^(-3/8)), -Inf, Inf);
risultato(i)=1-deltaS(i)+ctqST(i);
end
but I have a lot of warnings and the integral does not really work as it should (when it works, it give me a constant function, and sometimes matlab crash!).
What am I doing wrong?
(Maybe there is a simpler way to integrate and plot a function f(x)=int(g(x,y)dy) when g(x, y) diverges for some values... I don't know)
Thanks!
edit: I've also tried to use a simpler function (with no complex values), like
ctqST(i)=-integral(@(x)tanh(pi*(passo(i)-x)/10).*((x).^(-3/8)), 0, Inf);
but I still have problems...
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!