Invalid use of Operator error
Show older comments
I've written a simple script (from a textbook that too) but it doesn't run thanks to this error (Matlab Online R2020A). How do I fix the error and run the script?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1D transient heat conduction %
% space discretization: finite- %
% difference time integration: %
% Explicit Euler %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-- get initial wall time:
time0=clock();
%--- Simulation cell parameters:
Nx=128;
dx = 1.0;
%--- Time integration parameters:
nstep = 600; % no of integration steps
nprint = 200; % print frequency to output
dtime = 0.2;
%-- Initialize temperature field &
%grid:
for i=1:Nx
u0(i) = 0.0; % initial temp
x(i)= i*dx; % initialise 1d space grid
if((i >= 44) && (i <= 84))
u0(i)=1.0;
end
end
%--
%-- Evolve temperature field
%--
ncount=0;
for istep= 1:nstep % time summation
for i=2:Nx-1 % giving temp values at this time
u0(i) = u0(i) + dtime*1*(u0(i+1)-2.0*u0 . . .
(i)+u0(i-1)) . . .
/(dx*dx); % adding increment term!
end
%-- Display results:
if((mod(istep,nprint) == 0) ||(istep
== 1))
ncount=ncount+1;
subplot(2,2,ncount);
plot(x,u0);
time=sprintf('%d',istep);
title(['time' time]);
axis([0 Nx -0.5 1.5]);
xlabel('x');
ylabel('Temperature');
end %if
end %istep
compute_time=etime(clock(),time0); % for program efficiency!
fprintf('Compute Time: %5d\n',
compute_time);
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!