MATLAB Answers

Integration using symbolic, how about the constant?

2 views (last 30 days)
Gustav Svensson
Gustav Svensson on 6 Nov 2020
Commented: Paul on 9 Nov 2020
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);


Gustav Svensson
Gustav Svensson on 6 Nov 2020
Or can anyone please tell were the 2 comes from?
Paul on 9 Nov 2020
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)

Sign in to comment.

Answers (1)

Raunak Gupta
Raunak Gupta on 9 Nov 2020
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!


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!