Filter löschen
Filter löschen

Please help me how to calculate this double integral. It contains both a function and a matrix

1 Ansicht (letzte 30 Tage)
F and k are constants. E(x,y) is the input matrix. My code is:
function [E2] = image_generator_10(data_file,wavelength,focal_length)
% Calculating wave vector k
k = (2.*pi)/wavelength;
%Calculating constant value of the integral
coeff_1 = ( 1i.*k.*exp(-1i.*k.*2*focal_length) ) / (4.*pi.*focal_length);
%creating output matrix
E2 = zeros(10,10);
%Loop for u and v
for u = 1:0.011:10
for v = 1:0.011:10
%Computing the integral
fun = @(x,y) exp( ( -1i.*k.*(((u-x).^2) + (v-y).^2)) / (4.*focal_length) );
s = coeff_1.*exp(1i.*k.*(u.^2 + v.^2)/(4.*focal_length));
value = s*(trapz(trapz(data_file*fun)))*0.00021
E2(u,v) = value;
end
end
The error is
Undefined operator '*' for input arguments of type 'function_handle'.
Error in image_generator_10 (line 28)
value = s*(trapz(trapz(data_file*fun)))*0.00021
Can anyone help please!
  1 Kommentar
Walter Roberson
Walter Roberson am 20 Aug. 2018
You are creating a function handle, fun, that takes an x and y input. Then in
value = s*(trapz(trapz(data_file*fun)))*0.00021
you are trying to multiple data_file by fun. But fun is the function handle, not the result of executing the function at any particular location.
"E(x,y) is the input matrix"
Not in that equation it is not. The dx and dy tell you that E_I(x,y) in the equation has to be considered over the entire range -infinity to +infinity. That is not meaningful for a matrix, so it follows that E_I(x,y) must be a function rather than a matrix.
If your passed in data_file represents the previous evaluation of some E_I over a fixed set of coordinates, then you should be evaluating your fun at the same coordinates (whatever they are.) You should also be passing the coordinates in to trapz()

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by