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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by