필터 지우기
필터 지우기

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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by