I keep getting this error:

1 次查看(过去 30 天)
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 个)

Community Treasure Hunt

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

Start Hunting!

Translated by