Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Use a for loop to create a matrix called psiold that has vertical values spanning from 0 to 1 6 for every column.
Use a for loop to create a matrix called psiold that has vertical values spanning from to for
every column.
Create a zeroes matrix called psinew that is the same size as psiold.
Create a variable called tol that represents the tolerance limit at which the while loop will stop.
Set tol equal to
Create a variable called counter to track how many while loop iterations are done before the
tolerance is satisfied. Set counter equal to
Create a while loop that runs as long as there are any points at which abspsinewpsioldtol are
not satisfied. Remember that abspsinewpsioldtol is a logical expression that will returns s or
s depending on if the condition is satisfied or not. The while condition should have the logical
expression nested into another logical expression to account for there being any points where the
first logical expression is still true.
Nested within the while loop, created a nested for loop that evaluates psinewi,j as the average of
the four surrounding psiold points. See equation below:
Note that the boundary rows and columns need to be excluded from the nested for loop,
otherwise the expression will be trying to reference index values outside of psiold. The boundary
conditions will be addressed below.
Create a second for loop, still nested within the while loop, that defines the first column of psinew
as values spanning from to This should be the same as you did in step with the exception
that you are only doing it for the first columns, rather than all columns.
Define the last column of psinew as the same as the second to last column of psinew. This is still
nested within the while loop.
Define the first row of psinew as equal to This is still nested within the while loop.
Define the last row of psinew as equal to This is still nested within the while loop.
Define rows through and columns through of psinew as equal to zero. This is to account
for the area of no flow, as described in the previous figure.
Create an if statement, still nested within the while loop, that does the same logical check as was
created in step to see if there are any points where the tolerance is not satisfied. If the condition
is true, define psiold as psinew and define psinew as all zeros.
Increment the counter by and end the while loop.
Display the counter.
Create a contour plot of psinew, with streamlines.
Set the axis equal and label and title the contour plot.
What happens to the counter value as the tolerance is increased and decreased?
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