Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MATLAB % Step 1 : Create a matrix psiold with vertical values spanning from 0 to 1 6 for every column rows = 1 7
MATLAB
Step : Create a matrix psiold with vertical values spanning from to for every column
rows ; Number of rows
cols ; Number of columns
psiold repmat: cols;
Step : Create a zeros matrix psinew that is the same size as psiold
psinew zerosrows cols;
Step : Create a tolerance variable tol
tol ;
Step : Create a counter variable
counter ;
Step : While loop condition
while anyanyabspsinew psiold tol
Step : Nested for loop to update psinew excluding the boundaries
for i :rows
for j :cols
psinewijpsioldij psioldij psioldij psioldij;
end
end
Step : Define the first column of psinew as values spanning from to
psinew::;
Step : Define the last column of psinew as the same as the second to last column
psinew:cols psinew:cols;
Step : Define the first row of psinew as equal to
psinew:;
Step : Define the last row of psinew as equal to
psinewrows:;
Step : Define rows through and columns through of psinew as equal to zero
psinew::cols;
Step : If statement to check tolerance and update psiold and psinew
if anyanyabspsinew psiold tol
psiold psinew;
psinew zerosrows cols;
end
Step : Increment the counter
counter counter ;
end
Step : Display the counter
dispNumber of iterations: numstrcounter
Step : Create a contour plot of psinew
contourpsinew
Step : Set axis equal, label, and title the contour plot
axis equal
xlabelColumn Index'
ylabelRow Index'
titleContour Plot of psinew'
Step : Discussion of tolerance changes
As the tolerance is increased, the counter value number of iterations decreases
because the stopping criterion is met more quickly. Conversely, as the tolerance
is decreased, the counter value increases because it takes longer to satisfy
the stopping condition with a stricter tolerance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started