Symbolic integration: error
Hi to all,
I have been trying to write a piece of code to avoid doing some calculations: the purpose is to calculate the integral of a given function and the integrale of the norm squared of its gradient on a shape that resembles a disk with a point, all of which depend on a parameter r.
For the first test, I did the calculations by hand and everything worked. Then I tried to automate the process of calculating the gradient and its norm squared in two different ways, and in both of them the functions are calcukated but the program fails to calculate the integral.
I’ve attached both the wrking and non-working tests (sorry for the long lines, but the shape and the integral are not easy to express).
Thank you in advance!
%test1 working
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du2(x,y,r)=(y^2-r^2/(1-2*r)*x^2)^2*(4*(x-1+r)^2+4*y^2)+((x-1+r)^2+y^2-r^2)^2*(4*(r/sqrt(1-2*r))^4*x^2+4*y^2)-8*r^2/(1-2*r)*x*(x-1+r)*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2)+8*y^2*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2);
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test 2 not working (first way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du_body=formula(du);
du2(x,y,r)=du_body(1)^2+du_body(2)^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test2 not working (second way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du2(x,y,r)=(norm(du))^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));Hi to all,
I have been trying to write a piece of code to avoid doing some calculations: the purpose is to calculate the integral of a given function and the integrale of the norm squared of its gradient on a shape that resembles a disk with a point, all of which depend on a parameter r.
For the first test, I did the calculations by hand and everything worked. Then I tried to automate the process of calculating the gradient and its norm squared in two different ways, and in both of them the functions are calcukated but the program fails to calculate the integral.
I’ve attached both the wrking and non-working tests (sorry for the long lines, but the shape and the integral are not easy to express).
Thank you in advance!
%test1 working
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du2(x,y,r)=(y^2-r^2/(1-2*r)*x^2)^2*(4*(x-1+r)^2+4*y^2)+((x-1+r)^2+y^2-r^2)^2*(4*(r/sqrt(1-2*r))^4*x^2+4*y^2)-8*r^2/(1-2*r)*x*(x-1+r)*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2)+8*y^2*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2);
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test 2 not working (first way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du_body=formula(du);
du2(x,y,r)=du_body(1)^2+du_body(2)^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test2 not working (second way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du2(x,y,r)=(norm(du))^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r)); Hi to all,
I have been trying to write a piece of code to avoid doing some calculations: the purpose is to calculate the integral of a given function and the integrale of the norm squared of its gradient on a shape that resembles a disk with a point, all of which depend on a parameter r.
For the first test, I did the calculations by hand and everything worked. Then I tried to automate the process of calculating the gradient and its norm squared in two different ways, and in both of them the functions are calcukated but the program fails to calculate the integral.
I’ve attached both the wrking and non-working tests (sorry for the long lines, but the shape and the integral are not easy to express).
Thank you in advance!
%test1 working
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du2(x,y,r)=(y^2-r^2/(1-2*r)*x^2)^2*(4*(x-1+r)^2+4*y^2)+((x-1+r)^2+y^2-r^2)^2*(4*(r/sqrt(1-2*r))^4*x^2+4*y^2)-8*r^2/(1-2*r)*x*(x-1+r)*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2)+8*y^2*(y^2-r^2/(1-2*r)*x^2)*((x-1+r)^2+y^2-r^2);
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test 2 not working (first way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du_body=formula(du);
du2(x,y,r)=du_body(1)^2+du_body(2)^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
%test2 not working (second way)
syms x y r
u(x,y,r)=((x-1+r)^2+y^2-r^2)*(y^2-r^2/(1-2*r)*x^2);
du(x,y,r)=gradient(u, [x,y]);
du2(x,y,r)=(norm(du))^2;
intu= int( int(u,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(u,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r));
intdu2= int( int(du2,y,-sqrt(r^2-(x-1+r)^2),sqrt(r^2-(x-1+r)^2)), x, (1-2*r)/(1-r), 1) + int( int(du2,y,-r/sqrt(1-2*r)*x,r/sqrt(1-2*r)*x), x, 0, (1-2*r)/(1-r)); symbolic, integration, integral MATLAB Answers — New Questions