L = 0.8;c=1;T=0.5;a = 0 :120; it0 = inline('0.2.*sin(x)','x');M=80;N=50;dx=L/M;dt=T/N;for i = 1:M + 1, u(i,1) = it0(x(i));endr = c*(dt/dx); r1 = (r^2)/2; r2 = 2*(1 - (r^2));u(2:M,2) = r1*u(1:M - 1,1) + (1 - (r^2))*u(2:M,1) + r1*u(3:M + 1,1);for k = 3:N + 1u(2:M,k) = (r^2)*u(1:M - 1,k - 1) + r2*u(2:M,k-1) + (r^2)*u(3:M + 1,k - 1)...- u(2:M,k - 2); endfor n=1:N;figureplot(a,u(:,n));end
I want plot waveform graph that u(x,t) versus x, but come out error [??? Index exceeds matrix dimensions.
Error in ==> osc at 8 end ]
Can anyone help me fix the error?thanks..
Best Answer