Error: Operator '*' is not supported for operands of type 'function_handle'.

조회 수: 5 (최근 30일)
Apostolis
Apostolis 2022년 6월 5일
편집: Atsushi Ueno 2022년 6월 5일
Hello, I have the following code
clc; clear all; format long;
N=1024; L=100; x=(L/N)*(-N/2:N/2-1); dx=x(2)-x(1);
k=(2*pi/L)*[0:N/2-1 -N/2:-1];
w=10; uin=exp(-(x/w).^2); % initial condition
%figure(1); plot(x,abs(uin),'r');
a=0.1; d=10;
po=@(x) abs(x-0.05)<=0.05 | abs(x-10.15)<=0.05;
tiledlayout(1,2);
nexttile; fplot(po,[-0.1,0.2]); axis padded
nexttile; fplot(po,[9.9,10.3]); axis padded
S=1000; zmax=20; h=zmax/S; z=0; count=0; dim=0; savestep=10; u0=uin;
for m=1:S
u1=ifft(fft(u0).*exp(-1i*0.5*h*k.^2)); % First step of SSF
u2=exp(1i*h*po).*u1; % Second step of SSF
u3=ifft(fft(u2).*exp(-1i*0.5*h*k.^2)); % Second step of SSF
u0=u3; z=z+h; count=count+1;
if (count==savestep)
dim=dim+1; field(dim,:)=u0; pot(dim,:)=po; z1(dim)=z; count=0;
end;
end;
[X,Z]=meshgrid(x,z1);
figure(2); surf(X,Z,abs(field)); shading interp; view([0 90]); axis square; axis tight;
figure(3); surf(X,Z,pot); shading interp; view([0 90]); axis square; axis tight;
figure(4); plot(x,abs(field)); shading interp;
This gives me the error:
Operator '*' is not supported for operands of type 'function_handle'.
Error in Code_16_SSF_BPM_thin_film (line 15)
u2=exp(1i*h*po).*u1; % Second step of SSF
I know that the line 'po=@(x) abs(x-0.05)<=0.05 | abs(x-10.15)<=0.05;' is the problem, but I don't know what to do since I am now starting getting used to Matlab. Any help would be greatly appreciated.
  댓글 수: 1
Atsushi Ueno
Atsushi Ueno 2022년 6월 5일
편집: Atsushi Ueno 2022년 6월 5일
Argument x must be given to function po. ”po” without parentheses is a function handle.
u2=exp(1i*h*po).*u1;

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by