All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
clear all close all clc %% Defining the Mesh n_points = 50; dom_size = 1; h = dom_size/(n_points - 1); dt = 0.0001; alpha = dt/(h*h); %% Initializing the problem y(n_points, n_points) = 0; y(1,:) = 1; y_new(n_points , n_points) = 0; y_new(1,:) = 1; error_mag = 1; error_req = 1e-6; iterations = 0; %% Tracking the error…
Amith Ganta
updated on 23 May 2021
clear all
close all
clc
%% Defining the Mesh
n_points = 50;
dom_size = 1;
h = dom_size/(n_points - 1);
dt = 0.0001;
alpha = dt/(h*h);
%% Initializing the problem
y(n_points, n_points) = 0;
y(1,:) = 1;
y_new(n_points , n_points) = 0;
y_new(1,:) = 1;
error_mag = 1;
error_req = 1e-6;
iterations = 0;
%% Tracking the error magnitude
error_track = 0;
%%Calculations
while error_mag > error_req
for i = 2:(n_points - 1);
for j = 2:(n_points - 1);
y_new(i,j) = y(i,j)+ alpha.*(y(i-1,j)+ y(i+1,j) + y(i,j-1) + y(i,j+1) - 4*y(i,j));
end
end
iterations = iterations +1;
%% calculation of error magnitude
error_mag = 0;
for i = 2:(n_points - 1);
for j = 2:(n_points - 1);
error_mag = error_mag + abs(y(i,j) - y_new(i,j));
error_track(iterations) = error_mag;
end
end
if rem(iterations, 1000) == 0;
iterations
error_mag
end
% Assigning old to New
y = y_new;
end
%% Plotting
x_dom = ((1:n_points)-1).*h;
y_dom = 1-((1:n_points)-1).*h;
[X,Y] = meshgrid(x_dom,y_dom);
contourf(X,Y,y,12);
colorbar
xlabel('x');
ylabel('y');
%print(gcf,'Example.png','-dpng','-r300');
%Plot the error with time
figure;
time = dt.*(1:iterations);
plot(time, error_track)
% concept of sub plots
figure;
subplot(2,1,1);
plot(time,error_track);
subplot(2,1,2)
contourf(X,Y,y,12);
colorbar
Results
iterations =
1000
error_mag =
0.1081
iterations =
2000
error_mag =
0.0150
iterations =
3000
error_mag =
0.0021
iterations =
4000
error_mag =
2.8846e-04
iterations =
5000
error_mag =
4.0020e-05
iterations =
6000
error_mag =
5.5521e-06
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Quater car modelling using Matlab
Quarter Car model …
25 Sep 2023 03:07 PM IST
Pacjeka combined slip
Pacjeka Magic Tyre model Pacjeka Magic Tyre model was developed by Prof.Hans Bastiaan Pacejka and it is widely used to represent empirically and interpolate previously measured…
05 Jun 2023 02:04 PM IST
Longitudinal and Lateral brush tyre model using Matlab
Tyre Modeling A tyre model is a mathematical or an empirical representation of the mechanism…
16 May 2023 07:14 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.