# Need to apply trapezoidal rule for double integration with an array by using the for loop

11 vues (au cours des 30 derniers jours)
GAYTRI ARYA le 22 Juin 2021
Commenté : GAYTRI ARYA le 24 Juin 2021
z=(0:0.1:10);
F1= @(r1,r2)exp(-(r1.^2+r2.^2).*A).*exp(-i*B.*z.*(r1.^2+r2.^2)).*besseli(n,r1.*r2./(sig^2)).*r1.*r2;
I want to use trapezoidal numerical integration on the F1 for the variables r1 and r2 for which limits are 0 to 1, where z is a matrix. The direct command of integral2 cannot be applied due to the array function. I am stuck at first loop, where the error "Conversion to double from function handle is not possible" is showing. Please help. Thanks in advance.
for i=1:m
xi=i*h;
sumx(i)=@(r2)F1(xi);
i=i+1;
end
##### 0 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Sargondjani le 23 Juin 2021
There are two things that need correction:
1) Remove the line i=i+1. This is what the for loop does. (also don't use "i" in general because i=sqrt(-1)))
2) The funciton handle. I will try to explain how function handles work. I have a function:
F = @(a,b,X1,X2)a*X1.^2 + b*X2.^2;
a,b are parameters. I will set them, for example a=1, b=2;
Now i want to loop over X1, given values of a, b, and X2:
a=1;
b=2;
X2 = 0.1;
h=0.001;
y = NaN(1,m);
for ii = 1:m
X1 = ii*h;
y(1,ii) = F(a,b,X1,X2);
end
Now the value of F, given a,b,X1(ii),X2 are assigned to y(ii). I hope that clarifies something.
##### 5 commentairesAfficher 4 commentaires plus anciensMasquer 4 commentaires plus anciens
GAYTRI ARYA le 24 Juin 2021
Thank you so much, your last suggestion worked.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Loops and Conditional Statements 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!