フィルターのクリア

Can integral2 left a variable inside?

32 ビュー (過去 30 日間)
Guan Hao
Guan Hao 2024 年 7 月 21 日 5:12
回答済み: Walter Roberson 2024 年 7 月 21 日 20:25
Hi,everyone.There're three variables in my function,x,y and w.
I want to integral x and y first,but there were a variable w stuck in my function.Can I left it and integral x,y first? Thank you.
clear
L=0.1;
section=50;
a=L/2;
b=L/section;
v=3e8;
f1=1.2e9;
f2=4.8e9;
f3=7.5e9;
f4=10e9;
w1=(2*pi*f1);
w2=(2*pi*f2);
w3=(2*pi*f3);
w4=(2*pi*f4);
Z01=50;
Z02=75;
a0=(log(Z02/Z01))./(2.*L);
T=a;
Ub=a;
Lb=-a;
ub=a;
lb=-a;
k=6;
syms x y w
l=0:(2*L)/(2*k):L % Approximate sections dvided
sec=numel(l)-1;
% Cm0
for s=1:1:sec
for t=1:1:sec
for m=1:1:k
P1=matlabFunction(((cos((m.*pi.*(y))./a)).*(cos(2.*(x-y).*w./v))));
P2(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),Lb+l(t),@(x)x);
P3(1,m)=integral2(P1,Lb+l(s),Lb+l(s+1),@(x)x,Lb+l(t+1));
P{s,t}=(P2+P3) % s section multiply t section
end
end
  2 件のコメント
Umar
Umar 2024 年 7 月 21 日 8:20
編集済み: Walter Roberson 2024 年 7 月 21 日 19:07
Hi Guan,
That was a very good question. When dealing with multiple variables in an integration scenario, it is crucial to ensure that all variables are appropriately handled to achieve accurate results. In this case, the variable w appears in the integrand function, which might complicate the integration process if left unaddressed.To address the issue of the stuck variable w, one approach could involve separating the integration steps for x and y from the part of the code that involves w. By isolating the integrations for x and y, you can focus on resolving any dependencies on w separately.
Here is a modified version of the code snippet that separates the integration of x and y from the part involving w:
% Define the integrand function without the variable w
P1 = @(x, y) cos((m * pi * y) / a) * cos(2 * (x - y) / v);
% Perform integration for x and y separately
int_x = integral2(@(x, y) P1(x, y), Lb + l(s), Lb + l(s + 1), Lb + l(t), Lb + l(t + 1));
int_y = integral2(@(x, y) P1(x, y), Lb + l(s), Lb + l(s + 1), Lb + l(t), Lb + l(t + 1));
% Proceed with further computations using int_x and int_y
Please let me know if you have any further questions.
Guan Hao
Guan Hao 2024 年 7 月 21 日 9:22
Yeah,it works.However, I was confused if I can just neglect w, since it was inside the cosine function.

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

回答 (2 件)

Torsten
Torsten 2024 年 7 月 21 日 9:51
移動済み: Walter Roberson 2024 年 7 月 21 日 20:23
You cannot simply remove the w in your expression as suggested by @Umar. I'd do the general integration first and then substitute x and y according to the bounds you specified. The result will be symbolic expressions in w, not simple numbers.
L = 0.1;
a = L/2;
v = 3e8;
m = 3;
syms x y w real
expr = cos(m*sym(pi)*y/a).*cos(2*(x-y)*w/v)
expr = 
int(int(expr,x),y)
ans = 

Walter Roberson
Walter Roberson 2024 年 7 月 21 日 20:25
I want to integral x and y first,but there were a variable w stuck in my function.Can I left it and integral x,y first?
No, integral2() is strictly numeric. Every variable involved must have a numeric value (or be one of the two named parameters.)
Symbolic integration is the way to go for this task.

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by