# Some hard numerical integrations Specific example provided

Posted 8 years ago
5945 Views
|
12 Replies
|
8 Total Likes
|
 Hi everyone, Let's suppose that there is a function, R(x), with variable x, and R(x)= ? P(x,t) dt. P(x,t) is a function of x and t, but it is a very complicated integral, so no analytic solution is available. Another function is H(x, y)= h(y)* ? R(x)*f(x) dx. Here, f(x) and h(y) are functions of x and y respectively. R(x) is calculated before. I need to plot the relation between H(x, y) and y. The bounds of both integrals are known. Does anyone know how to do it numerically in Mathematica? I hope that I make my question clear enough. Thanks for any help that you can provide!! Cheers, Stven
12 Replies
Sort By:
Posted 8 years ago
 Thanks everyone for the informative reply. Very appreciated!!!
Posted 8 years ago
 Begin by using ?NumericQ with NIntegrate. See (http://support.wolfram.com/kb/12502) r[x_?NumericQ] := NIntegrate[p[x,t], {t,a,b}] Where a and b are the limits of the numerical Integration.
Posted 8 years ago
 If you're looking for something maybe more efficient and more clever, you can turn R(x)= ? P(x,t) dt from an integral equation into a differential equation. Now that it's a differential equation you can use NDSolve or ParametricNDSolve: https://reference.wolfram.com/language/ref/NDSolve.htmlhttps://reference.wolfram.com/language/ref/ParametricNDSolve.html
Anonymous User
Anonymous User
Posted 8 years ago
 Hi Sean, First, thanks for your awesome reply. It seems to be a promising way. The only thing that worries me is that my equation is slightly different than the examples in NDSolve and ParametricNDSolve. I can convert my equation into a differential equation, but my differential equation is in the form of R'(x)= P(x,t), {t, t0, t1}. I think this is different from the form that can be calculated by NDSolve and PatametricNDSolve. Regards,Stven
Posted 8 years ago
 Use NIntegrate to compute r[x] (here I use Mathematica notation and avoid capitalizing user-defined function names). Compute the integral of r[x]*f[x] also with NIntegrate (possibly it should just be done as a double integral). At that point you are pretty much done.I should remark that the subject header seems to be incorrect; I have not found a specific example anywhere in this.
Posted 8 years ago
 Hi Daniel, I apologize for the inappropriate subject header. Thanks for the reply!Best regards,Stven
Posted 8 years ago
 Hi Stven,you say you need the relation between H(x,y) and y. But H does not depend on x, because x is only a dummy variable of integration. Then you simply have H(y) = h(y)*const, with: $$\mbox{const} := \int\mbox{d}x \; f(x) \int \mbox{d}t \; P(x,t)$$ Regards -- Henrik
Posted 8 years ago
 Hi Henrik,Thanks a lot for the reply. Sorry if I didn't make my question clear. I think that my key point is how to compute R(x)= ? P(x,t) dt with known bounds numerically? As P(x,t) it too complicated with x and t correlated, there is no way to find an analytic solution. It will be greatly appreciated if you can provide me some helps on coding this. Thanks again.Best regards,Stven
Posted 8 years ago
 Hi Stven,The only thing I can think of is a rather brute-force and decidedly unelegant method: 1. Make a "sufficiently dense" (*) grid of points {x0, y0} in the (x,y}-plane. 2. Calculate your function H(x,y) on this grid. (3. This step is optional: Perhaps wrap an Interpolation command over the H(x,y} so as to get smooth connections between the grid points.) 4. Choose your fixed point x0 and plot H(x0, y) versus y.This is how I would try it. Almost certainly there are more efficient methods, but this is simple and I don't see why it wouldn't work.(*) Footnote re point 1: The "sufficiently dense" is the stumbling block of course. If you know next to nothing about H(x,y), you'll have to proceed by trial and error. The more you know about H, the smarter you can choose your grid: make the grid sparse in regions where H doesn't change much and dense in regions with dramatic gradients.Hope this works for you.RenĂ© Samson
Posted 8 years ago
 Hi Rene, Thanks a million for your reply. I am very new to Mathematica, also I have never used any other maths software like Matlab before. Would you mind to write down some relevant codes for this calculation? I will write down the steps that I don't know how to code. It will be greatly appreciated if you can provide any help.-----Let's suppose that there is a function, R(x), with variable x, and R(x)= ? P(x,t) dt. P(x,t) is a function of x and t-----How to define P as a function of x and t? Will mathematica be able to compute this integral given a small region like {t, t+0.1)----- Make a "sufficiently dense" () grid of points {x0, y0} in the (x,y}-plane----*How to define a grid? Can you show me the code for it? Will the grid in Mathematica be able to store an equation? When I successfully calculate the integral for each interval, {t, t+0.1}, how do I sum it to get R(x)? I may have a million equations stored in the grid and the sum of them, which gives me R(x), will be horrendous. Thanks again for any help if you can provide!! Best regards,Stven
Posted 8 years ago