Definite integration using int command

3 次查看(过去 30 天)
Firstly, I'm quite new with matlab
I am currently trying to do a definite integral with respect to y of a particular function. The function that I want to integrate is
(note that the big parenthesis is multiplying with the first factor - I can't get the latex to not make it look like power)
I have tried plugging the above integral into Desmos and it worked as intended. My plan was to vary the value of x and y and will be using for loop via matlab.
However, after trying to use the int function to calculate the definite integral with the code as follow:
h = 5;
a = 2;
syms y
x = 3.8;
p = 2.*x.^2+2.*a.*y;
q = x.^2+y.^2;
r = x.^2+a.^2;
f = (-1./sqrt(1-(p.^2./(4.*q.*r)))).*(2.*sqrt(q).*sqrt(r).*2.*a-p.*2.*y.*sqrt(r)./sqrt(q))./(4.*q.*r);
theta = int(f,y,a+0.01,h) %the integral is undefined at y=2, hence the +0.01
the result is not quite as expected
theta =
int(-((8*461^(1/2)*(y^2 + 361/25)^(1/2))/5 - (461^(1/2)*y*(8*y + 1444/25))/(5*(y^2 + 361/25)^(1/2)))/((1 - (4*y + 722/25)^2/((1844*y^2)/25 + 665684/625))^(1/2)*((1844*y^2)/25 + 665684/625)), y, 21/10, 5)
After browsing through various posts, the common mistake is the undefined interval but the +0.01 should have fixed it. Any guidance on what went wrong is much appreciated.
  2 个评论
jessupj
jessupj 2022-1-17
编辑:jessupj 2022-1-17
does this not simplify somehow?... the integrand looks like it might reduce nicely to the form du/sqrt(1-u) or similar.
Wisaruth Maethasith
I tried to simplify using wolfram - it did simplify into this.
Same problem persists when using this one though sadly.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-1-17
h = 5;
a = 2;
syms y
x = 3.8;
p = 2.*x.^2+2.*a.*y;
q = x.^2+y.^2;
r = x.^2+a.^2;
f = (-1./sqrt(1-(p.^2./(4.*q.*r)))).*(2.*sqrt(q).*sqrt(r).*2.*a-p.*2.*y.*sqrt(r)./sqrt(q))./(4.*q.*r);
temp = simplify(int(f,y,a,h))
temp = 
theta = rewrite(temp,'exp')
theta = 
  4 个评论
Paul
Paul 2022-1-18
Repeating the code from your answer:
h = 5;
a = 2;
syms y
x = 3.8;
p = 2.*x.^2+2.*a.*y;
q = x.^2+y.^2;
r = x.^2+a.^2;
f = (-1./sqrt(1-(p.^2./(4.*q.*r)))).*(2.*sqrt(q).*sqrt(r).*2.*a-p.*2.*y.*sqrt(r)./sqrt(q))./(4.*q.*r);
temp = simplify(int(f,y,a,h))
temp = 
simplify(temp,100)
ans = 
Any idea why the user has to do the simplify() twice? I mean, why doesn't the engine do simplify() internally? The engine could have come up with the solution pretty easily on its own; at least so it appears.
Also, I'm not clear on why this line worked:
rewrite(temp,'exp')
ans = 
I thought that rewrite() call is supposed to rewrite all "All trigonometric and hyperbolic functions including inverse functions" in temp and replace them with "exp, log". But temp doesn't have any of those types of functions and rewrite() actually resulted in an expression in terms of one of the functions that it was supposed to replace.
Walter Roberson
Walter Roberson 2022-1-18
You only need one simplify() if you give it enough steps. 10 is enough.
h = 5;
a = 2;
syms y
x = 3.8;
p = 2.*x.^2+2.*a.*y;
q = x.^2+y.^2;
r = x.^2+a.^2;
f = (-1./sqrt(1-(p.^2./(4.*q.*r)))).*(2.*sqrt(q).*sqrt(r).*2.*a-p.*2.*y.*sqrt(r)./sqrt(q))./(4.*q.*r);
temp = int(f,y,a,h)
temp = 
simplify(temp,10)
ans = 

请先登录,再进行评论。

类别

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

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by