Borrar filtros
Borrar filtros

I keep getting this error:

2 visualizaciones (últimos 30 días)
Gentian Zavalani
Gentian Zavalani el 3 de Jun. de 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))))];

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by