Integration over two variable dependent function

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 comentarios

Simon Chan
Simon Chan el 9 de Mzo. de 2022
for i=1:numel(x)
not for i=numel(x)
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)
It is working now.
Thanks guys

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Condensed Matter & Materials Physics en Centro de ayuda y File Exchange.

Preguntada:

el 9 de Mzo. de 2022

Comentada:

el 11 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by