Symbolic Integration Problem Using Symbolic Math Toolbox

Dear Matlab users,
I would like to get the integral of a function symbolically in MATLAB. However, MATLAB doesn't give me the integral of this function. Do you have any advice?
Thanks in advance.
MATLAB Codes to run:
clear all; clc;
syms a q mL y nL p s b yA yU mR nR r
KK5=sin(q*pi*(mR*y+nR)/a)*cos((r*pi*(mR*y+nR))/a)*cos((2*p*pi*y)/b);
K5=simplify((-1/2)*((a*r)/(q^2-r^2)*pi)*int(KK5,y,[yA yU]))
It gives me this result:
K5 =
-(a*r*pi*int(cos((pi*r*(nR + mR*y))/a)*sin((pi*q*(nR + mR*y))/a)*cos((2*pi*p*y)/b), y, yA, yU))/(2*(q^2 - r^2))

2 件のコメント

Walter Roberson
Walter Roberson 2022 年 8 月 31 日
Integral with respect to which variable? You did not specify a variable of integration, so int() is going to pick one.
Note: when you syms i and syms j then the i and j that result will just be normal variables, with no connection to sqrt(-1) and no connection to coordinate axes. int() will not recognize hyperbolic functions, or possibilities of rewriting in terms of exp()
ercan duzgun
ercan duzgun 2022 年 8 月 31 日
Thank you very much for your response. You are right to say that I didn't specify the variable of integration. I didn't notice at first. I have edited my codes according to your warnings. I also changed i and j variables to q and p variables.
However, I am still not receiving a normal integrated symbolic expression. Do you have any other advice?

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2022 年 8 月 31 日
編集済み: Torsten 2022 年 8 月 31 日

0 投票

syms par1 par2 par3 par4 par5
syms a q p s b mR nR r
syms y yA yU
K5 = cos(par1*y+par2)*sin(par3*y+par4)*cos(par5*y);
K55 = int(K5,y,yA,yU);
K55 = subs(K55,[par1 par2 par3 par4 par5],[q*pi*mR/a q*pi*nR/a r*pi*mR/a r*pi*nR/a 2*pi*p/b]);
K55 = (-1/2)*((a*r)/(q^2-r^2)*pi)*K55;
K55 = simplify(K55)
K55 = 

9 件のコメント

ercan duzgun
ercan duzgun 2022 年 8 月 31 日
Dear @Torsten, thank you very much. I didn't think like that before. Your response is very useful. I appreciate your response and help.
Torsten
Torsten 2022 年 8 月 31 日
Of course, special cases are excluded, e.g. a=0, b=0, q^2=r^2.
Paul
Paul 2022 年 8 月 31 日
Are all of those substitutions correct? It looks like par1 and par2 should be flipped with par3 and par4.
Any idea why using par1-5 and then subsing yields a closed form expression? That seems like a handy trick to remember.
ercan duzgun
ercan duzgun 2022 年 8 月 31 日
Dear @Paul, you are right. Those substitutions are not correct. I noticed that they are not correct. However, the methodology to get the integral is useful. I can edit the wrong subsitutions into correct form by myself. Thank you for your warning.
Torsten
Torsten 2022 年 8 月 31 日
Better flip "sin" and "cos" in K5 :-)
Paul
Paul 2022 年 8 月 31 日
Any insight into why using the par variables allowed int to find a closed from solution, when it couldn't using the original variables? That was very interesting to me.
Torsten
Torsten 2022 年 8 月 31 日
Up to here, it works.
One of the new big mysteries of the symbolic toolbox.
syms a q mL y nL p s b yA yU mR nR r
KK5=sin(q*pi*(mR*y+nR))*cos(r*pi*(mR*y+nR)/a)*cos(2*p*pi*y/b);
K5=(-1/2)*((a*r)/(q^2-r^2)*pi)*int(KK5,y,yA,yU);
simplify(K5)
ans = 
Paul
Paul 2022 年 8 月 31 日
It looks like a "divide by a" is missing in your expression for the argument of the sin(). For some reason, including that makes a big difference in the result. Still a mystery
syms a q mL y nL p s b yA yU mR nR r
% KK5=sin(q*pi*(mR*y+nR)) *cos(r*pi*(mR*y+nR)/a)*cos(2*p*pi*y/b);
KK5=sin(q*pi*(mR*y+nR)/a)*cos(r*pi*(mR*y+nR)/a)*cos(2*p*pi*y/b);
K5=(-1/2)*((a*r)/(q^2-r^2)*pi)*int(KK5,y,yA,yU);
simplify(K5)
ans = 
I wonder if there are some allowable values of the parameters (r,q, etc.) that make it not possible to evaluate the integral uniquely
Torsten
Torsten 2022 年 8 月 31 日
It looks like a "divide by a" is missing in your expression for the argument of the sin().
Yes, that's why I wrote: Up to here, it works.

サインインしてコメントする。

その他の回答 (1 件)

ercan duzgun
ercan duzgun 2022 年 8 月 31 日
編集済み: ercan duzgun 2022 年 8 月 31 日

0 投票

Dear @Torsten, and dear @Paul, ( and dear @Walter Roberson)
I tried to follow @Torsten's last suggestion. Actually, I tried to use both method, however I get different results. Do you have any idea on "why I am getting different results " while using two different codes ?
My codes are like this:
clear all;clc;
%method1
syms a r iv mR nR y yA yU mL nL b jv iv
KK5=sin(iv*pi*(mR*y+nR)/a)*cos(r*pi*(mR*y+nR)/a)*cos(2*jv*pi*y/b)
KKK5=int(KK5,y,[yA yU])
KKKK5=simplify(((-1/2)*((a*r)/((iv^2-r^2)*pi)))*KKK5)
%method2
syms y5 p5 y55 p55 y555
Y5=sin(y5*y+p5)*cos(y55*y+p55)*cos(y555)
YY5=int(Y5,y,[yA yU])
YYY5=subs(YY5,[y5 p5 y55 p55 y555],[(iv*pi*mR/a) (iv*pi*nR/a) (r*pi*mR/a) (r*pi*nR/a) (2*jv*pi/b)])
YYYY5=simplify(((-1/2)*((a*r)/((iv^2-r^2)*pi)))*YYY5)
num_KKK5=eval(subs(KKKK5,[a r iv mR nR y yA yU mL nL b jv],[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.25 0.35 0.45 0.55]))
num_YYYY5=eval(subs(YYYY5,[a r iv mR nR y yA yU mL nL b jv],[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.25 0.35 0.45 0.55]))
simplify(KKKK5-YYYY5)
num_KKK5-num_YYYY5
%---
I get : num_KKK5 = -0.0016 , however, num_YYYY5 = -3.2468e-04 . Why different results?
Dear @Torsten , in your last message, you wrote to integrate directly. I can use your code to integrate directly, without using par1 etc. If I use your codes, it can directly integrate without any problem. However, when I tried to use my codes like that in the attachement below (method1), it can not integrate directly. It gives me result as :
KKKK5 =
-(a*r*int(cos((pi*r*(nR + mR*y))/a)*sin((pi*iv*(nR + mR*y))/a)*cos((2*pi*jv*y)/b), y, yA, yU))/(2*pi*(iv^2 - r^2))

2 件のコメント

Torsten
Torsten 2022 年 8 月 31 日
After correcting some errors in your code, I get the same result for both approaches.
format long
syms a r iv mR nR y yA yU mL nL b jv iv
KK5=sin(iv*pi*(mR*y+nR)/a)*cos(r*pi*(mR*y+nR)/a)*cos(2*jv*pi*y/b);
KKK5=int(KK5,y,yA,yU);
KKKK5=simplify(((-1/2)*((a*r)/((iv^2-r^2)*pi)))*KKK5);
num_KKK5=double(subs(KKKK5,[a r iv mR nR y yA yU mL nL b jv],[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.25 0.35 0.45 0.55]))
num_KKK5 =
-0.001632012764608
%method2
syms y5 p5 y55 p55 y555
Y5=sin(y5*y+p5)*cos(y55*y+p55)*cos(y555*y);
YY5=int(Y5,y,yA,yU);
YYY5=simplify(((-1/2)*((a*r)/((iv^2-r^2)*pi)))*YY5);
YYYY5=subs(YYY5,[y5 p5 y55 p55 y555],[(iv*pi*mR/a) (iv*pi*nR/a) (r*pi*mR/a) (r*pi*nR/a) (2*jv*pi/b)]);
num_YYYY5=double(subs(YYYY5,[a r iv mR nR y yA yU mL nL b jv],[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.25 0.35 0.45 0.55]))
num_YYYY5 =
-0.001632012764608
ercan duzgun
ercan duzgun 2022 年 8 月 31 日
Dear @Torsten , thank you very much for your useful reply. I appreciate your response.
Kind regards,

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2022a

タグ

質問済み:

2022 年 8 月 31 日

コメント済み:

2022 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by