I keep getting this error:

1 Ansicht (letzte 30 Tage)
Gentian Zavalani
Gentian Zavalani am 3 Jun. 2013
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))))];

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Jun. 2013
You initialize x(:,1) but you use x(:,j) with j > 1
  2 Kommentare
Gentian Zavalani
Gentian Zavalani am 4 Jun. 2013
Could suggest me any solution please
Walter Roberson
Walter Roberson am 4 Jun. 2013
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Encryption / Cryptography finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by