Solving an integral with variable as upper limit and plotting the solution

8 ビュー (過去 30 日間)
David
David 2015 年 1 月 20 日
コメント済み: john zhang 2020 年 8 月 12 日
How can I solve an integral when the upper limit is a variable, and then plot the solution? My integral is as follows: Integral of e^(-(y^2))dy and my upper limit is x, while the lower limit is negative infinity. X and y are variables. I have tried using the trapz function, but then you must have a constant as upper limit. I have also tried using the int-funtion, but that is only solving for an indefinite integral. Does anyone know what I should do?

採用された回答

Torsten
Torsten 2015 年 1 月 20 日
Your function is equal to
sqrt(pi)/2*(1+erf(x))
Best wishes
Torsten.
  1 件のコメント
john zhang
john zhang 2020 年 8 月 12 日
what if the function is very complex and has no general antiderivative? Thank you

サインインしてコメントする。

その他の回答 (4 件)

Alessandro Masullo
Alessandro Masullo 2015 年 1 月 20 日
You can use cumsum or cumtrapz.

David
David 2015 年 1 月 20 日
Ok, thank you both for your answers. But I do not understand how I should write when I want to use a variable as the upper limit. How is that possible?

David
David 2015 年 1 月 20 日
I have now tried to use the while loop for some time and it looks like this:
upper_limit=-1;
while upper_limit<1
upper_limit=upper_limit+0.1;
theta=[-10^5:upper_limit];
y=(pi^(-(0.5)))*exp(-(theta.^2));
z=trapz(theta,y);
end
The problem now is that I only get the final answer to be z. I am not sure if this is correct, but is it possible to get all the answers into a vector som that it can be used in the plotting?
David
  4 件のコメント
David
David 2015 年 1 月 21 日
Thank you very much for new anwers. I have now tried to use the erf function for some time, but I have a problem. My error function had limits from negative infinity to x. X=[-0.5:0.5]. But the erf function has a lower boundary equal to 0. How is it possible to find the value when the lower boundary is negative infinity?
David
John D'Errico
John D'Errico 2015 年 1 月 21 日
You could just use basic calculus.
erf gives you the integral from 0 to x. If you want the integral from -inf to x, then add 1. This is because the integral from -inf to 0 is 1.
erf(-inf)
ans =
-1
(Beware of the order of those limits, which gives me here -1.)
So the integral from -inf to x is
1 + erf(x)
Which is valid for any real x as your upper limit.

サインインしてコメントする。


David
David 2015 年 1 月 21 日
Thank you very much all of you! Your help is very much appreciated. Now I understand how it can be computed in matlab, and how to find the integral from negative infinity to zero.
David

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by