Integration over two variable dependent function

조회 수: 1 (최근 30일)
Özgür Alaydin
Özgür Alaydin 2022년 3월 9일
댓글: Özgür Alaydin 2022년 3월 11일
Dear all,
I have function which generates 3d plot. I change the function to obtain data dependent on the two variables then function is giving zero except last term after integration.
The code is as given below. This is working as i want and giving the correct plot.
clear
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
[X,Y]=meshgrid(x,y);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
idx=(X/Rx1).^2 + (Y/Ry1).^2 < 1;
V0=(idx)*0 + (1-idx)*Vb1;
surf(x*1e9,y*1e9,V0)
However when i change the code as given below, it is not working, making all rows 0 except last one.
How can i correct it?
clear
Nx=50;
Ny=50;
Mx=20e-9;
My=20e-9;
x=linspace(-Mx/2,Mx/2,Nx);
y=linspace(-My/2,My/2,Ny);
Vb1=0.228;
Rx1=5e-9;
Ry1=5e-9;
alfa=0e-9; w=1E+12; T=2*pi/w;
T = 1.0;
for i=numel(x)
for j = 1:numel(y)
fx =@(t) x(i) + alfa.*sin(w.*t);
idx=@(t) (fx(t)./Rx1).^2 + (y(j)/Ry1).^2 < 1;
Vb = @(t) idx(t).*0 + (1-idx(t)).*Vb1;
V0(i,j) = (1/T).*integral(Vb,0,T,'ArrayValued',true);
end
end
surf(x*1e9,y*1e9,V0)
  댓글 수: 3
Torsten
Torsten 2022년 3월 9일
I must admit that I don't understand the function you are trying to integrate.
This gives you a code to integrate your original problem. Is it that what you want in a t-dependent form somehow ?
Vb1 = 0.228;
Rx1 = 5e0;
Ry1 = 5e0;
idx = @(x,y)(x/Rx1).^2 + (y/Ry1).^2 < 1;
V0 = @(x,y) idx(x,y)*0 + (1-idx(x,y))*Vb1;
V = integral2(V0,-10,10,-10,10)
Özgür Alaydin
Özgür Alaydin 2022년 3월 11일
It is working now.
Thanks guys

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by