how to solve error using integral
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Star Strider
am 14 Okt. 2021
Bearbeitet: Star Strider
am 14 Okt. 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 Kommentare
Mathieu NOE
am 14 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!