how to solve error using integral
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clear all
clc
qu=linspace(-2*pi,2*pi,126);
x=linspace(-2,2,126);
y=2*x;
psi=(-x./sqrt(qu/2)+sqrt(y)/sqrt(exp(-2*asinh(sin(qu/2)))+1));
ket=diff(psi);
bras=psi';
bras=bras(1:end-1);
for i=1:length(qu)-1
f(i)=bras(i)*ket(i);
end
phase=1i*integral(f,qu,-pi,pi)
% i am getting the following error:
Error using integral (line 82)
First input argument must be a function handle.
Error in test (line 15)
phase=1i*integral(f,qu,-pi,pi)
how can i solve this error?
thank you in advance
0 comentarios
Respuestas (2)
Star Strider
el 14 de Oct. de 2021
Editada: Star Strider
el 14 de Oct. de 2021
Not certain what the desired result is, however everything here are arrays or vectors, so use trapz instead, since there are no functions defined —
qu=linspace(-pi,pi,126);
x=linspace(-2,2,126);
y=2*x;
psi=(-x./sqrt(qu/2)+sqrt(y)/sqrt(exp(-2*asinh(sin(qu/2)))+1));
ket=gradient(psi,(x(2)-x(1))); % Use 'gradient' To Calculate The Numerical Derivative
bras=psi';
% bras=bras(1:end-1);
% for i=1:length(qu)-1
% f(i)=bras(i)*ket(i);
% end
f = bras .* ket;
% phase=1i*integral(f,qu,-pi,pi)
phase_columns = 1i*trapz(qu,f)
phase_rows = 1i*trapz(qu,f,2)
Experiment to get the desired result.
EDIT — (14 Oct 2021 at 12:42)
Originally forgot to multiply the trapz results by 1i, now included.
.
0 comentarios
Mathieu NOE
el 14 de Oct. de 2021
hello
integral works on function (handles) not arrays
f is an array , not a function handle so use trapz to do numerical integration
clear all
clc
qu=linspace(-2*pi,2*pi,126);
x=linspace(-2,2,126);
y=2*x;
psi=(-x./sqrt(qu/2)+sqrt(y)./sqrt(exp(-2*asinh(sin(qu/2)))+1));
ket=diff(psi);
bras=psi;
bras=bras(1:end-1);
f = bras.*ket(1:length(qu)-1);
phase=1i*trapz(qu(1:length(qu)-1),f)
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!