symbolic integrating only one variable of three

4 次查看(过去 30 天)
Hellow every one. I have one function with three variables. Variables typicaly are x,y,z where y=0 but in function i am using spherical coordinates which i have define in the begining of my code. I have one extra variable th1 which i want to integrate and the new function will have only x,z(r,th in spherical ). My problem is i cannot do that because when i run this:
syms x z th1;
r=(x^2 + z^2)^0.5;
th=acos(z/r);
d=2;
a=1;
d1=(a^2)/d;
L=1.5;
R1=(r^2 + d^2 - 2*r*d*(cos(th)*cos(th1) + sin(th)*sin(th1)))^0.5;
R2=(r^2 + d1^2 - 2*r*d1*(cos(th)*cos(th1) + sin(th)*sin(th1)))^0.5;
F1=d/R1;
F2=-(a/R2);
a1=-L/d;
a2=L/d;
f=@(x,z,th1)(F1+F2)
g = @(x,z) integral(@(th1) f(x,z,th1) , a1,a2)
I get :
f =
function_handle with value:
@(x,z,th1)(F1+F2)
I just want the symbolic expression of the above integration. I am stuck a lot of hours looking in already answered post but nothing so far. thanks in advance.

采纳的回答

Walter Roberson
Walter Roberson 2018-11-3
f = matlabFunction(F1+F2, 'vars', [x, z, th1]);
It turns out there is a closed form solution for g, but it is long and a bit complicated, and MATLAB cannot find it.
  9 个评论
Walter Roberson
Walter Roberson 2018-11-5
I will look at this later; I have an appointment to go to now.
Walter Roberson
Walter Roberson 2018-11-5
I ran that code preceded by
syms x z th1
and it worked. It did give two messages about
Warning: Infinite or Not-a-Number value encountered.
One of those messages is for (0,0). r(0,0) = 0, and so acos(z/r(x,z)) is acos(z/0) which is 0/0 which is nan. This is the case for all th1 for (0,0)
The other of the messages is for (0,2). F1(0,2,th1) = 2^(1/2)/(2*(1 - cos(th1))^(1/2)) and when th1 is sufficiently close to 0, 1-cos(th1) becomes 0, leading to a division by 0, which leads to an infinite result. This the case for two of the th1 values that are generated internally, both near +/- 7E-9, but it is enough to "poison" the entire integral, so g(0,2) is infinite.

请先登录,再进行评论。

更多回答(1 个)

madhan ravi
madhan ravi 2018-11-3
just change your last Line to this:
g = int( f(x,z,th1) ,th1, a1,a2)
  12 个评论
Walter Roberson
Walter Roberson 2018-11-5
-2*(-a^2+(b^2+c^2)^(1/2))*(-(sin(x-arctan(-b,c))*(b^2+c^2)^(1/2)+a^2)/(-a^2 +(b^2+c^2)^(1/2)))^(1/2)*(-(sin(x-arctan(-b,c))-1)*(b^2+c^2)^(1/2)/(a^2+(b^ 2+c^2)^(1/2)))^(1/2)*((sin(x-arctan(-b,c))+1)*(b^2+c^2)^(1/2)/(-a^2+(b^2+c^ 2)^(1/2)))^(1/2)*EllipticF((-(sin(x-arctan(-b,c))*(b^2+c^2)^(1/2)+a^2)/(-a^ 2+(b^2+c^2)^(1/2)))^(1/2),(-(-a^2+(b^2+c^2)^(1/2))/(a^2+(b^2+c^2)^(1/2)))^( 1/2))/(b^2+c^2)^(1/2)/cos(x-arctan(-b,c))/((a^2*(b^2+c^2)^(1/2)+b^2*sin(x- arctan(-b,c))+c^2*sin(x-arctan(-b,c)))/(b^2+c^2)^(1/2))^(1/2)
Is the antiderivative of that function, Torsten
Torsten
Torsten 2018-11-6
编辑:Walter Roberson 2018-11-6
My suggestion is to differentiate f with respect to r, set r=a and use "integral" to do the integration.
Interchanging integration and differentiation is justified by "Leibniz integral rule":
Best wishes
Torsten.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by