Matlab showing 'Index exceeds matrix dimensions.'Index exceeds matrix dimensions. Error in Final/oden (line 44) U = ys(1:N,1); Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0. Error in ode15s (
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
function Final_difference
clear clc close all format long
% Constant coefficient alpha = 1; beta = 1;
% Boundary condition l = 0; L = 1;
N = 50; x = linspace(l,L,N);% spial dx = x(2)-x(1);
% Timespan & Initial condition tf = 8; ns = 20; tspan = linspace(0,tf,ns); Uin = 1;
[t,s] = ode15s(@oden,tspan,Uin); plot(t,s) title('The solution of Heat equation') xlabel('time t') ylabel('concentration U')
%ODE15s function function F = oden(t,ys) U = ys(1:N,1); %F(3,1) = beta*((U(4)-2*U(3)+U(2))/dx)/dx+alpha*((U(4)-U(2))./(2*dx)) F(2:N-1,1) = (beta*(((U(3:N)-2*U(2:N-1)+U(1:N-2))/dx)/dx))+(alpha*(U(3:N)-U(1:N-2))./(2*dx)) % F(N,1)=(1/dx^2)*(U(N+1)-2*U(N)+U(N-1))+alpha*(U(N+1)-U(N-1))./2*dx end end
Trying to do a time integration for a finite difference method on matlab, but when I run it it keeps saying
Index exceeds matrix dimensions
Error in Final/oden (line 44) U = ys(1:N,1);
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 148) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Final (line 34) [t,s] = ode15s(@oden,tspan,Uin);
Anyone know what is wrong?
Thanks
0 Kommentare
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!