![777.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/207511/777.png)
How to fix "Undefined function 'sinc' for input arguments of type 'double'." Error
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ege Tunç
am 8 Mär. 2019
Kommentiert: Sean
am 14 Mai 2023
I found a code to use for my project far field diffraction generator however, I got an error called, Undefined function 'sinc' for input arguments of type 'double'.
How can i fix this?
Here is my code:
%------------------------------------------------------------------------
%-----Fraunhofer diffraction from a rectangular aperture-----------------
%------------------------------------------------------------------------
clc
close all
clear all
%------------------------------------------------------------------------
lambda=500e-9; k=(2*pi)/lambda; % wavelength of light in vaccuum
a=1e-6; b=1e-6; % dimensions of diffracting rectangular aperture
% a is along Z and b is along Y
Io=100.0; % relative intensity
R=1.0e-3; % distance of screen from aperture
Y=(-0.25e-2:1e-5:0.25e-2); Z=Y ; % coordinates of screen
beta=k*b*Y/(2*R*pi);alpha=k*a*Z./(2*R*pi); % intermediate variable
% diffracted intensity
for i=1:length(Y)
for j=1:length(Z)
I(i,j)=Io.*((sinc(alpha(j)).^2).*(sinc(beta(i))).^2);
end
end
%------------------------------------------------------------------------
figure(1)
imshow(I)
title('Fraunhofer Diffraction','fontsize',14)
fh = figure(1);
set(fh, 'color', 'white');
%------------------------------------------------------------------------
0 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 8 Mär. 2019
Bearbeitet: KALYAN ACHARJYA
am 8 Mär. 2019
I didnot find any error, when I run the code in my system (2015b)
clc;
clear all;
close all;
lambda=500e-9; k=(2*pi)/lambda; % wavelength of light in vaccuum
a=1e-6; b=1e-6; % dimensions of diffracting rectangular aperture
% a is along Z and b is along Y
Io=100.0; % relative intensity
R=1.0e-3; % distance of screen from aperture
Y=(-0.25e-2:1e-5:0.25e-2); Z=Y ; % coordinates of screen
beta=k*b*Y/(2*R*pi);alpha=k*a*Z./(2*R*pi); % intermediate variable
% diffracted intensity
for i=1:length(Y)
for j=1:length(Z)
I(i,j)=Io.*((sinc(alpha(j)).^2).*(sinc(beta(i))).^2);
end
end
%------------------------------------------------------------------------
figure(1)
imshow(I)
title('Fraunhofer Diffraction','fontsize',14)
fh = figure(1);
set(fh, 'color', 'white');
%------------------------------------------------------------------------
![777.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/207511/777.png)
3 Kommentare
Steven Lord
am 8 Mär. 2019
The sinc function is defined in Signal Processing Toolbox (for numeric arrays) and Symbolic Math Toolbox (for symbolic arrays.) You didn't have Signal Processing Toolbox installed before but now you do.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!