Integration using symbolic, how about the constant?

39 ビュー (過去 30 日間)
Gustav Svensson
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 件のコメント
Gustav Svensson
Gustav Svensson 2020 年 11 月 6 日
Or can anyone please tell were the 2 comes from?
Paul
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
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!

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by