Effacer les filtres
Effacer les filtres

Integration over two variable dependent function

2 vues (au cours des 30 derniers jours)
Özgür Alaydin
Özgür Alaydin le 9 Mar 2022
Commenté : Özgür Alaydin le 11 Mar 2022
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 commentaires
Torsten
Torsten le 9 Mar 2022
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 le 11 Mar 2022
It is working now.
Thanks guys

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by