Integration using symbolic, how about the constant?

조회 수: 78(최근 30일)
Gustav Svensson
Gustav Svensson 2020년 11월 6일
댓글: Paul 2020년 11월 9일
I have som trouble to understand how the int function is used.
I want to solve the integration constant myself. But matlab gives a constant in the int step.
This line gives
-(g*(2*cos(t*w) + t*w + 2))/(2*w)
Which is wrong in my opinion. The solution is -(g*(2*cos(t*w) + t*w ))/(2*w) + C
Which means that C have already been calculated (C=-g/w). How can I prevent matlab from calculating C? So i can add C by myself.
(I understand that i can add the same constant v=int(a,t)+g/w. But then i need to calculate the constant first..)
This is my code:
syms t g w c1
a= g*sin(w*t)-g/2;
C1_ =solve(subs(v1,t,ll)==0,c1);
  댓글 수: 2
Paul 2020년 11월 9일
It appears that the 2 comes from the original solution of int being in an unexpected form, at least unexpected to me:
>> int(g*sin(t*w),t)
ans =
>> int(-g/2,t)
ans =
>> v=int(a,t) % interesting result, but not wrong?
v =
- (g*t)/2 - (2*g)/(w*(tan((t*w)/2)^2 + 1))
>> simplify(v)
ans =
-(g*(2*cos(t*w) + t*w + 2))/(2*w)

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


Raunak Gupta
Raunak Gupta 2020년 11월 9일
From the documentation of int, you can see it is clearly mentioned that constant of integration is not returned since the constant can be represented in any way and it can lead to huge complexity if expanding the expression. Since constant of integration in this case returned can be something else if the expression changes to some other form, it is not included in the outputs. If you want to represent the constant of integration you can add it in result as a symbolic variable.
syms x C1
f (x) = x;
g = int (f, x) + C1;
From this too you can estimate the C1.
For the comment I can tell that constant of integration that is returned is not universal and can change if you give the expression differently.
If numerical computation is required, definite integral can be used by providing the limits which will give full answer correctly.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by