We begin this lab by developing some graphical tool to better visualise to solutions to dif-...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
We begin this lab by developing some graphical tool to better visualise to solutions to dif- ferential equations. We begin with Quiver plots: A quiver plot is used to display a two di- mensional vector field. It is called in python with plt.quiver. This function requires four arguments, all of which must be arrays of the same size. The first two arguments define a grid of (x, y) points. The grid can be created using the meshgrid function in numpy: |X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, 2)) This creates a 2-dimensional grid of points in the range 0 to 2 in the x and y directions. The next arguments specify the components of a 2-dimensional vector, V(x, y) = (Vx(x, y), Vy(x, y)), at the corresponding grid points. Python will draw an arrow at each grid point to represent the vector field V(x, y). As an example; define the vector field, V(Vx, Vy), as: Vx = np.cos (X) Vy = np. sin (Y) Implement and run the following code illustrating how to make a quiver plot, as well as affect figure size, geometry and labelling: import matplotlib.pyplot as plt import numpy as np np.meshgrid(np. arange (0, 2 np.pi, .2), np.arange (0, 2* np.pi, .2)) plt.close() X, Y = Vx = np.cos(X) Vy np.sin(Y) = plt.figure (figsize=(6,6)) plt.gca ().set_aspect ('equal', adjustable='box') #Make plot box square plt.xlabel('x') plt.ylabel('y') plt.title('Example of a quiver plot') plt.quiver (X, Y, Vx, Vy, pivot='mid', label='$V_x$ plt.legend () plt.show() = cos ($x$), $V_y$ = sin ($y$)') 6 5 4 31 2 1 Example of a quiver plot | V₁ = cos(x), V, = sin(y) > 3 0- Quiver plot with reduced density V = cos(x), Vy= sin(y) 4 (a) (b) Figure 1: Examples of quiver plots for the vector field defined by (cos(x), sin(y)) for different grid densities and plot options The code should produce a plot as shown in Fig. 1(a) Note that at each gridpoint the arrow is proportional to the magnitude and direction of the vector V at that point. Vary the grid density and explain what you are observing: It is possible to add a legend for the arrow lengths on to the quiver plot as follows: Q-plt.quiver (X, Y, U, V, pivot='mid', label='$V_x$ = cos($x$), $V_y$ = sin($y$)') plt.quiverkey (Q, 0.9, 0.9, 2, r'$2\frac{m} {s}$', labelpos='E', coordinates='figure') One can produces a less dense quiver plot without redefining the original array by omit- ting points in the original array. On can use an addition of a scatter plot to add a red dot at the grid points. The result of these modifications is shown in Fig. 1(b). Q-plt.quiver (X[::3, ::3], Y[::3, ::3], Vx[::3, 1:3], Vy[::3, ::3], pivot='mid', label='$V_x$ = cos ($x$), $V_y$ = sin($y$)') plt.quiverkey (Q, 0.9, 0.9, 2, r'$2\frac{m} {s}$', labelpos='E', coordinates='figure') plt.scatter (X[::3, ::3], Y[::3, ::3], color='r', s=10) A detailed description of the quiver command can be found with the help command help (plt.quiver), or online. We begin this lab by developing some graphical tool to better visualise to solutions to dif- ferential equations. We begin with Quiver plots: A quiver plot is used to display a two di- mensional vector field. It is called in python with plt.quiver. This function requires four arguments, all of which must be arrays of the same size. The first two arguments define a grid of (x, y) points. The grid can be created using the meshgrid function in numpy: |X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, 2)) This creates a 2-dimensional grid of points in the range 0 to 2 in the x and y directions. The next arguments specify the components of a 2-dimensional vector, V(x, y) = (Vx(x, y), Vy(x, y)), at the corresponding grid points. Python will draw an arrow at each grid point to represent the vector field V(x, y). As an example; define the vector field, V(Vx, Vy), as: Vx = np.cos (X) Vy = np. sin (Y) Implement and run the following code illustrating how to make a quiver plot, as well as affect figure size, geometry and labelling: import matplotlib.pyplot as plt import numpy as np np.meshgrid(np. arange (0, 2 np.pi, .2), np.arange (0, 2* np.pi, .2)) plt.close() X, Y = Vx = np.cos(X) Vy np.sin(Y) = plt.figure (figsize=(6,6)) plt.gca ().set_aspect ('equal', adjustable='box') #Make plot box square plt.xlabel('x') plt.ylabel('y') plt.title('Example of a quiver plot') plt.quiver (X, Y, Vx, Vy, pivot='mid', label='$V_x$ plt.legend () plt.show() = cos ($x$), $V_y$ = sin ($y$)') 6 5 4 31 2 1 Example of a quiver plot | V₁ = cos(x), V, = sin(y) > 3 0- Quiver plot with reduced density V = cos(x), Vy= sin(y) 4 (a) (b) Figure 1: Examples of quiver plots for the vector field defined by (cos(x), sin(y)) for different grid densities and plot options The code should produce a plot as shown in Fig. 1(a) Note that at each gridpoint the arrow is proportional to the magnitude and direction of the vector V at that point. Vary the grid density and explain what you are observing: It is possible to add a legend for the arrow lengths on to the quiver plot as follows: Q-plt.quiver (X, Y, U, V, pivot='mid', label='$V_x$ = cos($x$), $V_y$ = sin($y$)') plt.quiverkey (Q, 0.9, 0.9, 2, r'$2\frac{m} {s}$', labelpos='E', coordinates='figure') One can produces a less dense quiver plot without redefining the original array by omit- ting points in the original array. On can use an addition of a scatter plot to add a red dot at the grid points. The result of these modifications is shown in Fig. 1(b). Q-plt.quiver (X[::3, ::3], Y[::3, ::3], Vx[::3, 1:3], Vy[::3, ::3], pivot='mid', label='$V_x$ = cos ($x$), $V_y$ = sin($y$)') plt.quiverkey (Q, 0.9, 0.9, 2, r'$2\frac{m} {s}$', labelpos='E', coordinates='figure') plt.scatter (X[::3, ::3], Y[::3, ::3], color='r', s=10) A detailed description of the quiver command can be found with the help command help (plt.quiver), or online.
Expert Answer:
Answer rating: 100% (QA)
To vary the grid density in the quiver plot and observe the differences you can adjust the slicing i... View the full answer
Related Book For
An Introduction to Statistical Methods and Data Analysis
ISBN: 978-1305269477
7th edition
Authors: R. Lyman Ott, Micheal T. Longnecker
Posted Date:
Students also viewed these programming questions
-
Define the N- dimensional characteristic function for a random vector, X = [X1, X2,..XN] T , according to X () = E[ejTX] where = [1, 2, N] T. Show that the - dimensional characteristic function for...
-
To plot y = sin(x), we must define vectors of x and y values and then use the plot command. This can be done as follows: x = 0:0.1:6.3; y = sin(x); plot(x, y) (a) Let us define a rotation matrix and...
-
NumPy package of Python can be used to calculate the mean measure. A) True B) False
-
Calculate the heat released as 35.5 g of copper (0.0920 cal/g x C) cools from 50.0 C to 25.0 C.
-
List the two approaches to examining a firms long-term debt-paying ability. Discuss why each of these approaches gives an important view of a firms ability to carry debt.
-
Identify three or four products for which you feel appeals to guilt might be a viable approach to persuading consumer acceptance of a brand. What kinds of products do not lend themselves to such...
-
Markup. In this exercise, we introduce the concept of markup. The markup on an item is the difference between how much a store sells an item for and how much the store paid for the item. Suppose...
-
Assume that the nation of Spain is small and unable to influence the Brazilian (world) price of steel. Spains supply and demand schedules are illustrated in Table. Assume that Brazils price is $400...
-
Michael Dundee is sileduring a savings education programi fOf Is SOTI, JIIIIIIly WI 13 years old. Jimmy plans to enrol at the university in 5 years, and it should take hi to complete his degree in...
-
On January 1, 2024, Harlon Consulting entered into a three-year lease for new office space agreeing to lease payments of $5,000 in 2024, $6,000 in 2025, and $7,000 in 2026. Payments are due on...
-
Scenario 4, do you think the speculative transaction is profitable for the company? A. Selling Speculation Transactions with Forward Contracts On November 1, 2015, PT Perkasa purchased a 180-day...
-
Which of the following is not one of the independent auditors objectives regarding the examination of inventories? a. Verifying that inventory counted is owned by the client b. Verifying that the...
-
During the audit of a new client, you uncover an accounting policy stating that all purchases of equipment or other items under $500 will be expensed, regardless of their nature. When you ask the...
-
Inshalla Retail Company keeps its inventory on a perpetual FIFO basis for internal reporting, but adjusts the year-end FIFO balance to a LIFO basis using a dollar-value LIFO index. The auditor is...
-
How can analytical procedures be applied to accounts receivable?
-
Assume that you have just gone to work for Wipfli, Barber, & Zeitlow, a regional CPA firm with seven offices in your state. The company is interested in automating much of its documentation. The...
-
Vulcan Flyovers offers scenic overflights of Mount Saint Helens, the volcano in Washington State that explosively erupted in 1982. Data concerning the company's operations in July appear below....
-
Use the graphs of f and g to graph h(x) = (f + g) (x). To print an enlarged copy of the graph, go to MathGraphs.com. 1. 2. y 24 8. 2. -2 -2 4 6
-
Refer to Example 8.6. The political action group was interested in determining regional differences in the publics opinion concerning air pollution. Write a contrast in the four population means to...
-
Mason, Gunst, and Hess (2003) describe the following study. A traffic engineer designs a study to compare the total unused red- light times for five methods of traffic- light signaling (A, B, C, D,...
-
Refer to Exercise 11.65. a. Estimate the mean fuel usage for a 1000- mile flight. Provide a 95% confidence interval for your estimate. b. Predict the fuel usage for a particular 1000- mile flight....
-
What information in a companys annual report would be important to an investor who is interested in its corporate bonds?
-
What are three pieces of information about corporate bonds that you could find in the bond section of a newspaper?
-
Tom and Rika Nagata plan to retire in ten years. In 2004, they purchased three bonds: Two 20-year AT&T corporate bonds, each with a face value of \($1,000\) and 7 percent annual interest. The...
Study smarter with the SolutionInn App