Can integral2 left a variable inside?

4 次查看(过去 30 天)
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
编辑:Walter Roberson 2024-7-21
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
Yeah,it works.However, I was confused if I can just neglect w, since it was inside the cosine function.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2024-7-21
移动:Walter Roberson 2024-7-21
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 = 
  3 个评论
Torsten
Torsten 2024-7-23
编辑:Torsten 2024-7-23
How can the integration results be "numbers" if w is an unspecified variable in the integrand ? integral3 would not help in this case, either.
Guan Hao
Guan Hao 2024-7-23
@Torsten Because I got about 10 other functions of w to integrte . If I use integral3 to run,it's too slow.
That's why I want to integrate x and y first, and save w to the last.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2024-7-21
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 CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by