i got some issues trying to integrate a function symbolically

I'm trying to symbolically integrate this function, but it's not working:
>> syms x y s
>> fun = y/((x-s)^2+y^2);
>> int(fun,s,-l/2,l/2)
ans =
int(y/((s - x)^2 + y^2), s, -l/2, l/2)
why does matlab return me an expression the same as what I typed????? I want an integral in symbolic form instead. The function is to be integrated with respect to variable s only from -l/2 to +l/2 (lower case L)

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 14일
편집: Ameer Hamza 2020년 11월 14일
For a general case, the solution might not be expressed in an analytical form. But if x and y are assumed to be real, then you can get an expression
syms x y s l
assume([x y], 'real')
fun = y/((x-s)^2+y^2);
I = int(fun,s,-l/2,l/2)
Result
>> I
I =
atan((l - 2*x)/(2*y)) + atan((l + 2*x)/(2*y))

댓글 수: 5

by the way, if I want to plot a contour plot of this function atan((l - 2*x)/(2*y)) + atan((l + 2*x)/(2*y)), how should I do it? I made a meshgrid of x,y and here's what I did:
>> [x,y] = meshgrid(-1:0.1:1,-1:0.1:1);
>> l = 1;
>> contour(c)
Error using contour (line 46)
Input arguments must be numeric or objects which can be converted to double.
i set c = atan((l - 2*x)/(2*y)) + atan((l + 2*x)/(2*y))
Following shows one way to do this
syms x y s l
assume([x y], 'real')
fun = y/((x-s)^2+y^2);
I = int(fun,s,-l/2,l/2);
Ifun = matlabFunction(I, 'Vars', {'x', 'y', 'l'});
[xg,yg] = meshgrid(-1:0.01:1);
lv = 1;
Iv = Ifun(xg, yg, lv);
contour(Iv)
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2020년 11월 14일

댓글:

2020년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by