Filter löschen
Filter löschen

Can integral2 left a variable inside?

32 Ansichten (letzte 30 Tage)
Guan Hao
Guan Hao am 21 Jul. 2024 um 5:12
Beantwortet: Walter Roberson am 21 Jul. 2024 um 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 Kommentare
Umar
Umar am 21 Jul. 2024 um 8:20
Bearbeitet: Walter Roberson am 21 Jul. 2024 um 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 am 21 Jul. 2024 um 9:22
Yeah,it works.However, I was confused if I can just neglect w, since it was inside the cosine function.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Torsten
Torsten am 21 Jul. 2024 um 9:51
Verschoben: Walter Roberson am 21 Jul. 2024 um 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 am 21 Jul. 2024 um 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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by