Index exceeds matrix dimensions.

조회 수: 2 (최근 30일)
mohamed elkasemy
mohamed elkasemy 2019년 2월 12일
답변: Cris LaPierre 2019년 2월 13일
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