# Integration using symbolic, how about the constant?

조회 수: 78(최근 30일)
Gustav Svensson 2020년 11월 6일
댓글: Paul 2020년 11월 9일
Hi,
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.
v=int(a,t);
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..)
Br
This is my code:
syms t g w c1
a= g*sin(w*t)-g/2;
ll=pi/6/w;
ul=5*pi/6/w;
v=int(a,t);
v1=v+c1;
C1_ =solve(subs(v1,t,ll)==0,c1);
simplify(C1_)
v=v+C1_;
simplify(v)
s=int(v,t,ll,ul);
s=vpa(s)
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
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 =
-(g*cos(t*w))/w
>> int(-g/2,t)
ans =
-(g*t)/2
>> 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)

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

### 답변(1개)

Raunak Gupta 2020년 11월 9일
Hi,
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!

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

### 범주

Find more on Logical in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by