I keep getting this error:

1 回表示 (過去 30 日間)
Gentian Zavalani
Gentian Zavalani 2013 年 6 月 3 日
clear all
M=input('Enter M =')
N=input('Enter N=')
r=input('Enter r=')
f=input('Enter f=')
L=pi;
h=L/M;
%------&------------------------&------------------------------&-----------------*
%Ne kete program behet zgjidhja numerike e nje problemi diferencial valor
%me shuarje kufitare.Metoda e perdorur eshte ajo e tipit te
%karakteristikave .Ajo shfrytezon rrjetin specifik te nyjeve qe gjenerojne
%kurbat karakterisitke te ekuacionit si dhe vecorite e kushteve
%fillestare-kufitare te problemit
%-------&-----------------------&---------------------------------&--------------*
for i=1:M+1
x(i,1)=i*h;
u(i,1)=sin(x(i,1));
xu(i,1)=cos(x(i,1)); %derivati ne lidhje me x;
tu(i,1)=cos(x(i,1)); %derivati ne lidhje me t;
end
for j=1:N+1
for i=2:M
xu(x(i,j+1))=1/2*[cos(x(i,j))+cos(x(i-1,j))+cos(x(i,j))-cos(x(i-1,j))]+h/8*[r*(cos(x(i,j))-(1/f)*(cos(x(i,j))))-r*(cos(x(i-1,j))-(1/f)*(cos(x(i-1,j))))];
tu(x(i,j+1))=1/2*[cos(x(i,j))-cos(x(i-1,j))+cos(x(i,j))+cos(x(i-1,j))]+h/8*[r*(cos(x(i,j))-(1/f)*(cos(x(i,j))))+2*(r*(cos(x(i,j+1))-(1/f)*(cos(x(i,j+1)))))+r*(cos(x(i-1,j))-(1/f)*(cos(x(i-1,j))))];
u(x(i,j+1))=1/2*[sin(x(i-1,j))+sin(x(i,j))]+h/8*[cos(x(i-1,j))-cos(x(i,j))+cos(x(i-1,j))+2*cos(x(i,j+1))+cos(x(i,j))];
end
end
------------------------------------------------------------------------------
??? Index exceeds matrix dimensions.
Error in ==> MOC at 30
xu(x(i,j+1))=1/2*[cos(x(i,j))+cos(x(i-1,j))+cos(x(i,j))-cos(x(i-1,j))]+h/8*[r*(cos(x(i,j))-(1/f)*(cos(x(i,j))))-r*(cos(x(i-1,j))-(1/f)*(cos(x(i-1,j))))];

採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 3 日
You initialize x(:,1) but you use x(:,j) with j > 1
  2 件のコメント
Gentian Zavalani
Gentian Zavalani 2013 年 6 月 4 日
Could suggest me any solution please
Walter Roberson
Walter Roberson 2013 年 6 月 4 日
You need to assign values to x(i,j) at some point, but I do not know where would be appropriate. My guess would be that it should be done before the "for j" loop, instead of only initializing x(i,1)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEncryption / Cryptography についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by