Symbolic Integration Problem Using Symbolic Math Toolbox

2 次查看(过去 30 天)
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
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 个评论
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
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,

请先登录,再进行评论。

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by