How to use trapz or cumtrapz function to integrate a function from -infinity to t?

7 views (last 30 days)
clc;
close all;
clear all;
p = 2;
num_gamma= gamma(3/p);
den_gamma= gamma(1/p);
global a;
a=(p/2)*(((num_gamma)^(1/2))/((den_gamma)^(3/2)))
global b;
b=(num_gamma/den_gamma)^(p/2)
tau = -100:0.01:100;
for t = 1:length(tau)
f(t)=a*(exp(-b*((abs(tau(t)))*p)));
** F=cumtrapz(tau,f(t));**
g=(f.^2)./(1-F);
end
plot(g,tau)
------------------
I NEED TO INTEGRATE THE FUNCTION 'f' FROM MINUS INFINITY TO tau, HOW CAN I DO THAT?

Answers (1)

John D'Errico
John D'Errico on 30 May 2016
Please don't ask the same question over and over again. I'll answer this only because it is SLIGHTLY different from your other nearly identical question.
trapz and cumtrapz cannot solve problems on an infinite domain. Well, they can, but it will take infinitely long, and require an infinitely large computer. Infinity is a big place.
Of course, you can try a transformation of your function, to convert the infinite domain into a finite one. Not all transformations will work well here, but that is a question of mathematics, not MATLAB.
  6 Comments
John D'Errico
John D'Errico on 30 May 2016
Edited: John D'Errico on 31 May 2016
John - Infinity IS far away, if you are trying to use a tool like trapz. In fact, that makes the problem impossible to solve using trapz directly.
And I DID tell you how to solve the problem of an infinite integral. The use of a transformation is a classical solution.
Or, if you have an understanding of your problem, then you can truncate the problem.
Finally, you can use other tools, perhaps a Gaussian integration, chosen from a class appropriate for your specific problem. (There are lots of tricks one could try. Much depends on your mathematical abilities.)
Of course, all of these require some knowledge of both the specific problem, and some understanding of the mathematics. If you are trying to solve this type of problem, then it would seem one should understand the mathematics.
Walter Roberson
Walter Roberson on 31 May 2016
"Depending on the value of the charge the field may be null a couple feet away from the charge."
Only if you have shielding, or the initial charge is 0. Otherwise at any given distance you have reduced charge but not non-zero. Place two electrons at mutual rest a light year away from each other and they will affect each other.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!