Index exceeds matrix dimensions.

1 次查看(过去 30 天)
clc;
clear all;
close all;
g = 1;
m = 1;
M = 1;
T = 1;
fun = @(x,y,V,T) ((2*pi*g*(1-(V.^2)).^2)/m^2).*y.*(((x-(m*V./sqrt(1-V.^2))).^2./(1-(V).^2))+y.^2).*exp(-(sqrt(m^2+x.^2+y.^2)-M)/T);
QQ_pl = @(V,T) integral2(@(y,x) fun(x,y,V,T), 0, inf, -inf, m*V./sqrt(1-V.^2));
QQ_mi = @(V,T) integral2(@(y,x) fun(x,y,V,T), 0, inf, m*V./sqrt(1-V.^2), inf);
V(1)=0.1
L=0;
dL=0.01;
t(1)=L+dL;
dV(1)=(QQ_mi(V(1),T(1))-QQ_pl(V(1),T(1)))*t(1)
for i=2:50
t(i)=L+i*dL;
dV(i)=(QQ_mi(V(i-1),T(i-1))-QQ_pl(V(i-1),T(i-1)))*t(i)
V(i)=V(i-1)-dV(i)
end
plot(t,V)

采纳的回答

Cris LaPierre
Cris LaPierre 2019-2-13
You define T as a scalar
T = 1
but then in your for loop try to index out values from it like it is a vector
dV(i)=(QQ_mi(V(i-1),T(i-1))-QQ_pl(V(i-1),T(i-1)))*t(i)
You will therefore get this error message any time i>2 (since index is T(i-1)).
Just like you add values to V in each loop, you likely need to do something similar for T.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by