how to solve error using integral

1 visualización (últimos 30 días)
Rabih Sokhen
Rabih Sokhen el 14 de Oct. de 2021
Editada: Star Strider el 14 de Oct. de 2021
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

Respuestas (2)

Star Strider
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_columns =
0.7046 - 0.0743i 0.7075 - 0.0746i 0.7133 - 0.0752i 0.7193 - 0.0758i 0.7254 - 0.0765i 0.7317 - 0.0771i 0.7382 - 0.0778i 0.7448 - 0.0785i 0.7516 - 0.0792i 0.7586 - 0.0800i 0.7658 - 0.0807i 0.7732 - 0.0815i 0.7808 - 0.0823i 0.7886 - 0.0831i 0.7967 - 0.0840i 0.8051 - 0.0849i 0.8137 - 0.0858i 0.8226 - 0.0867i 0.8318 - 0.0877i 0.8413 - 0.0887i 0.8511 - 0.0897i 0.8613 - 0.0908i 0.8719 - 0.0919i 0.8829 - 0.0931i 0.8943 - 0.0943i 0.9061 - 0.0955i 0.9184 - 0.0968i 0.9313 - 0.0982i 0.9447 - 0.0996i 0.9587 - 0.1011i 0.9733 - 0.1026i 0.9887 - 0.1042i 1.0048 - 0.1059i 1.0217 - 0.1077i 1.0394 - 0.1096i 1.0582 - 0.1116i 1.0780 - 0.1136i 1.0989 - 0.1159i 1.1212 - 0.1182i 1.1448 - 0.1207i 1.1700 - 0.1233i 1.1969 - 0.1262i 1.2258 - 0.1292i 1.2568 - 0.1325i 1.2904 - 0.1360i 1.3268 - 0.1399i 1.3665 - 0.1441i 1.4100 - 0.1487i 1.4579 - 0.1537i 1.5111 - 0.1593i 1.5705 - 0.1656i 1.6376 - 0.1727i 1.7142 - 0.1807i 1.8026 - 0.1900i 1.9064 - 0.2010i 2.0305 - 0.2141i 2.1827 - 0.2301i 2.3757 - 0.2505i 2.6320 - 0.2775i 2.9971 - 0.3160i 3.5846 - 0.3779i 4.8494 - 0.5113i 7.2088 + 3.2068i 4.6396 + 6.3816i 0.5113 + 4.8494i 0.3779 + 3.5846i 0.3160 + 2.9971i 0.2775 + 2.6320i 0.2505 + 2.3757i 0.2301 + 2.1827i 0.2141 + 2.0305i 0.2010 + 1.9064i 0.1900 + 1.8026i 0.1807 + 1.7142i 0.1727 + 1.6376i 0.1656 + 1.5705i 0.1593 + 1.5111i 0.1537 + 1.4579i 0.1487 + 1.4100i 0.1441 + 1.3665i 0.1399 + 1.3268i 0.1360 + 1.2904i 0.1325 + 1.2568i 0.1292 + 1.2258i 0.1262 + 1.1969i 0.1233 + 1.1700i 0.1207 + 1.1448i 0.1182 + 1.1212i 0.1159 + 1.0989i 0.1136 + 1.0780i 0.1116 + 1.0582i 0.1096 + 1.0394i 0.1077 + 1.0217i 0.1059 + 1.0048i 0.1042 + 0.9887i 0.1026 + 0.9733i 0.1011 + 0.9587i 0.0996 + 0.9447i 0.0982 + 0.9313i 0.0968 + 0.9184i 0.0955 + 0.9061i 0.0943 + 0.8943i 0.0931 + 0.8829i 0.0919 + 0.8719i 0.0908 + 0.8613i 0.0897 + 0.8511i 0.0887 + 0.8413i 0.0877 + 0.8318i 0.0867 + 0.8226i 0.0858 + 0.8137i 0.0849 + 0.8051i 0.0840 + 0.7967i 0.0831 + 0.7886i 0.0823 + 0.7808i 0.0815 + 0.7732i 0.0807 + 0.7658i 0.0800 + 0.7586i 0.0792 + 0.7516i 0.0785 + 0.7448i 0.0778 + 0.7382i 0.0771 + 0.7317i 0.0765 + 0.7254i 0.0758 + 0.7193i 0.0752 + 0.7133i 0.0746 + 0.7075i 0.0743 + 0.7046i
phase_rows = 1i*trapz(qu,f,2)
phase_rows =
2.1086 - 3.3722i 2.0765 - 3.3401i 2.0441 - 3.3077i 2.0114 - 3.2750i 1.9785 - 3.2421i 1.9453 - 3.2088i 1.9117 - 3.1753i 1.8779 - 3.1415i 1.8438 - 3.1074i 1.8094 - 3.0730i 1.7747 - 3.0382i 1.7396 - 3.0032i 1.7041 - 2.9677i 1.6684 - 2.9320i 1.6322 - 2.8958i 1.5957 - 2.8593i 1.5588 - 2.8224i 1.5215 - 2.7851i 1.4838 - 2.7474i 1.4457 - 2.7092i 1.4071 - 2.6707i 1.3680 - 2.6316i 1.3285 - 2.5921i 1.2885 - 2.5521i 1.2480 - 2.5116i 1.2070 - 2.4706i 1.1654 - 2.4290i 1.1232 - 2.3868i 1.0805 - 2.3441i 1.0371 - 2.3007i 0.9930 - 2.2566i 0.9483 - 2.2119i 0.9029 - 2.1665i 0.8567 - 2.1203i 0.8097 - 2.0733i 0.7619 - 2.0255i 0.7132 - 1.9768i 0.6636 - 1.9272i 0.6130 - 1.8766i 0.5613 - 1.8249i 0.5086 - 1.7722i 0.4547 - 1.7182i 0.3994 - 1.6630i 0.3429 - 1.6065i 0.2848 - 1.5484i 0.2252 - 1.4888i 0.1638 - 1.4274i 0.1006 - 1.3642i 0.0352 - 1.2988i -0.0324 - 1.2312i -0.1026 - 1.1610i -0.1756 - 1.0880i -0.2519 - 1.0117i -0.3319 - 0.9317i -0.4163 - 0.8473i -0.5058 - 0.7578i -0.6014 - 0.6621i -0.7048 - 0.5588i -0.8181 - 0.4455i -0.9448 - 0.3188i -1.0914 - 0.1722i -1.2717 + 0.0081i -1.5336 + 0.2700i -1.5336 + 0.9856i -1.2717 + 1.2475i -1.0914 + 1.4278i -0.9448 + 1.5744i -0.8181 + 1.7011i -0.7048 + 1.8144i -0.6014 + 1.9178i -0.5058 + 2.0135i -0.4163 + 2.1029i -0.3319 + 2.1873i -0.2519 + 2.2673i -0.1756 + 2.3436i -0.1026 + 2.4167i -0.0324 + 2.4868i 0.0352 + 2.5545i 0.1006 + 2.6198i 0.1638 + 2.6831i 0.2252 + 2.7444i 0.2848 + 2.8041i 0.3429 + 2.8621i 0.3994 + 2.9187i 0.4547 + 2.9739i 0.5086 + 3.0278i 0.5613 + 3.0806i 0.6130 + 3.1322i 0.6636 + 3.1828i 0.7132 + 3.2324i 0.7619 + 3.2811i 0.8097 + 3.3289i 0.8567 + 3.3759i 0.9029 + 3.4221i 0.9483 + 3.4675i 0.9930 + 3.5123i 1.0371 + 3.5563i 1.0805 + 3.5997i 1.1232 + 3.6424i 1.1654 + 3.6846i 1.2070 + 3.7262i 1.2480 + 3.7672i 1.2885 + 3.8078i 1.3285 + 3.8478i 1.3680 + 3.8873i 1.4071 + 3.9263i 1.4457 + 3.9649i 1.4838 + 4.0030i 1.5215 + 4.0407i 1.5588 + 4.0780i 1.5957 + 4.1149i 1.6322 + 4.1515i 1.6684 + 4.1876i 1.7041 + 4.2234i 1.7396 + 4.2588i 1.7747 + 4.2939i 1.8094 + 4.3286i 1.8438 + 4.3631i 1.8779 + 4.3972i 1.9117 + 4.4310i 1.9453 + 4.4645i 1.9785 + 4.4977i 2.0114 + 4.5306i 2.0441 + 4.5633i 2.0765 + 4.5957i 2.1086 + 4.6278i
Experiment to get the desired result.
EDIT — (14 Oct 2021 at 12:42)
Originally forgot to multiply the trapz results by 1i, now included.
.

Mathieu NOE
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)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by