Answered step by step
Verified Expert Solution
Link Copied!

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.

1. Use a for loop to create a matrix called psiold that has vertical values spanning from 0 to 16 for
every column.
2. Create a zeroes matrix called psinew that is the same size as psiold.
3. Create a variable called tol that represents the tolerance limit at which the while loop will stop.
Set tol equal to 0.001.
4. Create a variable called counter to track how many while loop iterations are done before the
tolerance is satisfied. Set counter equal to 0.
5. Create a while loop that runs as long as there are any points at which abs(psinew-psiold)>tol are
not satisfied. Remember that abs(psinew-psiold)>tol is a logical expression that will returns 1s or
0s 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.
6. 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:
,=(+1,+,+1+1,+,1)/4
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.
7. Create a second for loop, still nested within the while loop, that defines the first column of psinew
as values spanning from 0 to 16. This should be the same as you did in step 1 with the exception
that you are only doing it for the first columns, rather than all columns.
8. 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.
9. Define the first row of psinew as equal to 0. This is still nested within the while loop.
10. Define the last row of psinew as equal to 16. This is still nested within the while loop.
11. Define rows 1 through 9 and columns 21 through 29 of psinew as equal to zero. This is to account
for the area of no flow, as described in the previous figure.
12. Create an if statement, still nested within the while loop, that does the same logical check as was
created in step 5 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.
13. Increment the counter by 1 and end the while loop.
14. Display the counter.
15. Create a contour plot of psinew, with 16 streamlines.
16. Set the axis equal and label and title the contour plot.
17. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

Pinpoint major guidelines for effective use of PowerPoint.

Answered: 1 week ago