Numerical Integration of symbolic expression.
2 ビュー (過去 30 日間)
古いコメントを表示
I have a lengthy symbolic expression in 3 variables say f(r,z,t). I want to integrate this expression over r and z (for specific numeric valued bounds say r=0 to 1, z=0 to 1). It is too long to use the symbolic integrator int(). So what I am asking is, is there a way to numerically integrate a symbolic expression? One way to do this would be to create two functions such that f(r,z,t)=g(t)*h(r,z) and then numerically integrate h(r,z). My expressions are very long and there is no way to to this expansion by hand. So is there a function that creates two functions g and h such that f(r,z,t)=g(t)*h(r,z). Any help would be great!!
Thanks
Drew
0 件のコメント
回答 (3 件)
Star Strider
2016 年 3 月 15 日
If ‘r’, ‘z’ and ‘t’ ar independent of one another, perhaps the easiest way might be to create 2D matrices for ‘r’ and ‘z’ with meshgrid, calculate ‘h(r,z)’ from them, integrate it with two calls to trapz, then create a vector for ‘t’, evaluate ‘g(t)’, integrate it with trapz, then multiply them. This involves a lot of assumptions that you didn’t state in your Question, but then it’s all we have.
2 件のコメント
Star Strider
2016 年 3 月 15 日
If you have a function ‘f(r,z,t)’ and it meets the requirements of the integral3 function, you could possibly use it. If they are vector-valued, you would have to use the integral function iteratively on it three times.
Walter Roberson
2016 年 3 月 15 日
It is not possible in general to numerically integrate a symbolic function for two of the three variables : if you do not know the range of the third variable then you cannot generally predict the possible range of numeric error so you would not know how tightly you need to integrate numerically on the two known variables in order to produce a result that will be within a specific tolerance.
2 件のコメント
Walter Roberson
2016 年 3 月 15 日
No, there is no general way to do a numeric integration on only some variables of a symbolic expression, leading to a symbolic result in the remaining variables.
The exception would be if you could divide the formula into the sum of (A) constant terms; and (B) terms that involve the variables to be integrated over but none of the variables that remain; and (C) terms that involve the variables to remain but none of the variables to be integrated over. If you can find an addend that has none of the terms to be left symbolic then you can do a numeric integration over that, but any addend that involves a mix of variables to be left symbolic and variables that remain, cannot be numerically integrated.
In the case of a function separable to g(t) * h(r,z) then g(t) might have terms that are constant in t, g(t) = u(t) + v, and h(r,z) might have terms that are constant in r and z, h(r,z) = w(r,z) + x, with every term of u(t) involving t, every term of v independent of t, every term of w(r,z) involving r or z, and every term of x independent of r, z, and t. Then g(t)*h(r,z) = u(t) * w(r,z) + v * w(r,z) + u(t) * x + v * x . Of these, v * w(r,z) + v*x can be numerically integrated, and u(t) * x can be left symbolic, but u(t) * w(r,z) is inherently unseparable and involves r and z, but the expression cannot be numerically integrated because the integration of the w(r,z) part cannot know the order of magnitude of the u(t) part and so cannot predict how fine-grained its numeric integration needs to be in order to achieve any particular target precision.
So what we are back to is that you need a function that can separate f into g(t) * h(r,z) . That is something I have not answered as yet, as I am still thinking about it.
Walter Oevel
2016 年 3 月 21 日
Hi Drew,
the function to do the factorization f(t,r,z) = g(t)*h(r,z) is the function 'factor' of the Symbolic Tool Box. ;-)
It does not know much of special functions (i.e., it wouldn't realize that exp(t+r+z) can be factored), but apart from that, the separation ansatz works if and only 'factor' splits the expression into some factors that depend only on t and others that depend only on r and z.
>> syms r z t >> factor(exp(t)*sin(r+z))
ans =
[ exp(t), sin(r + z)]
You might want to consider a more generalized separation such as f(t,r,z) = sum( g_i(t) * h_i(r, z), i = 1..n) with different factorizations g_i, h_i, but there would not be a system function to find g_i, h_i.
3 件のコメント
Walter Roberson
2016 年 3 月 21 日
I knew from a previous question that the poster knew about factor() so I suspect that for some reason factor() is not sufficient for them. Possibly because it can take a long time?
Walter Oevel
2016 年 3 月 22 日
Time is certainly an issue when the input is huge.
However, I guess the problem is more the fact that the chances of separation are quite small. Even generalizing the concept to f(t,r,z) = sum( g_i(t) * h_i(r, z), i = 1..n) works only for specific functions f(t,r,z). More generally, one would like to allow n = Inf, i.e., we would be talking about representations of an arbitrary function (square-integrable, say) by an infinite series of separated functions. Example: higher dimensional Fourier series expansion. Nothing like that is available in the symbolic engine.
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!