Matlab command window showing error and no working fine

11 views (last 30 days)
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);
U0 = 1; U_in = U0*ones(N,1); % at t=0 figure (1);
[t,s] = ode15s(@oden,tspan,U_in);
% Another way for ploting, haven't figured it out whether to use it or not % Usol = s(:,1:N); % Usol(10,end) % figure(1); % box on % hold on % subplot(2, 1, 1) % plot([x], [Usol(1:10:ns,:)],'b'); % xlabel ('space x'); % ylabel('U');
plot(t,s(:,1)) title('The solution of Heat equation') xlabel('time t') ylabel('concentration U')
%ODE15s function function F = oden(t,ys) % F is same as dudt, U = ys(1:N,1); % F(1,1)=(1/dx^2)*(2*U(2)-2*U(1))+alpha*(2*U(2))./2*dx % 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
Just update something, it gets better but still not working properly.
This is what the command window is showing. Error using odearguments (line 92) FINAL/ODEN returns a vector of length 49, but the length of initial conditions vector is 50. The vector returned by FINAL/ODEN and the initial conditions vector must have the same number of elements.
Error in ode15s (line 148) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Final (line 37) [t,s] = ode15s(@oden,tspan,U_in);

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!