Index exceeds matrix dimensions.

2 Ansichten (letzte 30 Tage)
mohamed elkasemy
mohamed elkasemy am 12 Feb. 2019
Beantwortet: Cris LaPierre am 13 Feb. 2019
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)

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 13 Feb. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by