I want to Calculate how much Time my code take to simulate. What changes in the code should be considered

2 views (last 30 days)
close all clc %Input paramters nx=10; %Number of grid points ny=nx; x=linspace(0,1,nx); y=linspace(0,1,ny); dx= x(2)-x(1); dy=dx; %Error criteria error=1; tolerance=1e-6; %Defining Boundary Conditions T_L=100; T_T=400; T_R=300; T_B=200; T=300*ones(nx,ny); T(2:ny-1,1)=T_L; T(2:ny-1,nx)=T_R; T(1,2:nx-1)=T_T; T(ny,2:nx-1)=T_B; %Calcualting Average temp at corners T(1,1)=(T_T+T_L)/2; T(nx,ny)=(T_R+T_B)/2; T(1,ny)=(T_T+T_R)/2; T(nx,1)=(T_L+T_B)/2; %Assigning Orginal Values to T T_initial=T; T_old=T; % Jacobi method iterative_solver=1; if iterative_solver==1 jacobi_iteration=1; while(error>tolerance) for i=2:nx-1 for j=2:ny-1 T(i,j)=0.25*(T_old(i-1,j)+T_old(i+1,j)+T_old(i,j+1)+T_old(i,j-1)); end end error=max(max(abs(T_old-T))); T_old=T; jacobi_iteration=jacobi_iteration+1; end end %plotting graphs figure() contourf(x,y,T) clabel(contourf(x,y,T)) colorbar colormap(jet) set(gca,'ydir','reverse') xlabel("X Axis") ylabel("Y Axis") title(sprintf("No of Jacobi iterations(Implicit)=%d", jacobi_iteration));

Accepted Answer

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh on 6 Sep 2021
use :
tic;
%% Your Code
toc % or Time = toc;
the output of calling toc, return how much time it takes from tic, to toc.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by