Question

Please read these instructions before you attempt to solve this problem. Download the live script file MAT343lab2ex4.mlx and open it with MATLAB. Run the file and use the information provided to complete the following exercise. For your convenience, a PDF version is also provided. Before you attempt this exercise, you might want to watch the last video of the video tutorials for this lab. The product y = Ax of an m x n matrix A times a column vector x = (x_(1), x_(2), ..., x_(n))^(T) can be computed row-wise as below: y = [A(1,2) * x; A(2,z) * x, ..., A(m,2) * x] that is y(1) = A(1,2) * x y(2) = A(2,:) * x y(m) = A(m,2) * x Write a function named myrowproduct that takes in input a matrix A, a column vector x, and a random number k, and as output gives the product y = Ax computed by row as defined above, and the intermediate value, z, of the output vector at the end of k iterations (this intermediate value is used by MATLAB Grader to determine whether your code is correct). Specific instructions for writing the function: - Extract the dimension of A using the command size and store the result in the variables m and n. - Extract the dimension of x using the command size and store the result in the variables p and q. - Use an if statement to perform a check on the dimensions to determine whether the multiplication is defined and whether x is a column vector. - If the multiplication is defined and x is a column vector: - Initialize the vector y as a vector of zeros of the appropriate dimension. - Use a single for loop to evaluate the entries of the product y = Ax. The loop counter should be the variable i. Each iteration of the for loop should evaluate the ith component of the vector y as the product of the ith row of A times the vector x. Also, inside the for loop, after you compute the ith component of y, insert the following:

          Please read these instructions before you attempt to solve this problem. Download the live script file MAT343lab2ex4.mlx and open it with MATLAB. Run the file and use the information provided to complete the following exercise. For your convenience, a PDF version is also provided. Before you attempt this exercise, you might want to watch the last video of the video tutorials for this lab.

The product y = Ax of an m x n matrix A times a column vector x = (x_(1), x_(2), ..., x_(n))^(T) can be computed row-wise as below:
y = [A(1,2) * x; A(2,z) * x, ..., A(m,2) * x]
that is
y(1) = A(1,2) * x
y(2) = A(2,:) * x
y(m) = A(m,2) * x

Write a function named myrowproduct that takes in input a matrix A, a column vector x, and a random number k, and as output gives the product y = Ax computed by row as defined above, and the intermediate value, z, of the output vector at the end of k iterations (this intermediate value is used by MATLAB Grader to determine whether your code is correct).

Specific instructions for writing the function:
- Extract the dimension of A using the command size and store the result in the variables m and n.
- Extract the dimension of x using the command size and store the result in the variables p and q.
- Use an if statement to perform a check on the dimensions to determine whether the multiplication is defined and whether x is a column vector.
- If the multiplication is defined and x is a column vector:
  - Initialize the vector y as a vector of zeros of the appropriate dimension.
  - Use a single for loop to evaluate the entries of the product y = Ax. The loop counter should be the variable i. Each iteration of the for loop should evaluate the ith component of the vector y as the product of the ith row of A times the vector x. Also, inside the for loop, after you compute the ith component of y, insert the following:
        
Show more…
please read these instructions before you attempt to solve this problem download the live script file mat343lab2ex4mlx and open it with matlab run the file and use the information provided t 65264

Added by Erica D.

Close

Elementary and Intermediate Algebra
Elementary and Intermediate Algebra
Alan S. Tussy, R. David Gustafson 5th Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
Please read these instructions before you attempt to solve this problem. Download the live script file MAT343lab2ex4.mlx and open it with MATLAB. Run the file and use the information provided to complete the following exercise. For your convenience, a PDF version is also provided. Before you attempt this exercise, you might want to watch the last video of the video tutorials for this lab. The product y = Ax of an m x n matrix A times a column vector x = (x_(1), x_(2), ..., x_(n))^(T) can be computed row-wise as below: y = [A(1,2) * x; A(2,z) * x, ..., A(m,2) * x] that is y(1) = A(1,2) * x y(2) = A(2,:) * x y(m) = A(m,2) * x Write a function named myrowproduct that takes in input a matrix A, a column vector x, and a random number k, and as output gives the product y = Ax computed by row as defined above, and the intermediate value, z, of the output vector at the end of k iterations (this intermediate value is used by MATLAB Grader to determine whether your code is correct). Specific instructions for writing the function: - Extract the dimension of A using the command size and store the result in the variables m and n. - Extract the dimension of x using the command size and store the result in the variables p and q. - Use an if statement to perform a check on the dimensions to determine whether the multiplication is defined and whether x is a column vector. - If the multiplication is defined and x is a column vector: - Initialize the vector y as a vector of zeros of the appropriate dimension. - Use a single for loop to evaluate the entries of the product y = Ax. The loop counter should be the variable i. Each iteration of the for loop should evaluate the ith component of the vector y as the product of the ith row of A times the vector x. Also, inside the for loop, after you compute the ith component of y, insert the following:
Close icon
Play audio
Feedback
Powered by NumerAI
Jennifer Stoner Danielle Fairburn
Kathleen Carty verified

Sri K and 74 other subject Algebra educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
note-this-problem-uses-ihe-same-setup-as-the-jacobi-and-gauss-seidel-questions-but-you-are-asked-calculate-dilferent-values-it-will-probably-be-useful-copy-code-from-ihose-problems-but-make-94627

Note: This problem uses the same setup as the Jacobi and Gauss-Seidel questions, but you are asked to calculate different values. It will probably be useful to copy code from those problems, but make sure that you alter your final answers accordingly. Any matrix A can be decomposed into a diagonal, upper and lower part: so that A = D + U + L. You can easily find these matrices in Matlab with the commands diag, triu and tril. These matrices are useful for devising different matrix splitting methods. For instance, in the Jacobi method we let A = P + T where P = D and T = U + L, and in the Gauss-Seidel method we set P = D + L and T = U. Another common matrix splitting method is called successive over-relaxation (SOR). It is exactly the same as the splitting methods we have already seen, except we set P = 1/w D + L and T = (w-1)/w D + U, where w is a constant between 1 and 2. (Notice that if w = 1 then this is exactly the same as Gauss-Seidel.) We will use this method to solve the system A_103 phi = rho that was described in the Jacobi and Gauss-Seidel problems. As a reminder, the setup for those problems is included at the bottom of this page. I have not included pretests for A, rho or phi in this problem, since you already know how to define them. Instead, you should define the matrices D, U and L for this problem and save them in variables named D, U and L. For any given w, the SOR method can be written as phi_k = M phi_{k-1} + c. For w = 1.6, find the largest (in magnitude) eigenvalue of M and save its magnitude in a variable named ans1. (Remember that you can find the magnitude of a number in Matlab with the abs command. Your answer should be a positive real number.) For every value of w between w = 1 and w = 1.99 in increments of 0.01, find the largest (in magnitude) eigenvalue of M. Find the value of w that gives you the smallest maximum eigenvalue and save this w in a variable named ans2. (That is, find the value of w for which this matrix splitting method will converge the fastest.) Use SOR to solve for phi with the optimal w you found in ans2. Your initial guess should be a vector of all 1's and you should stop when ||phi_k - phi_{k-1}||_inf < 10^-5. (These are the same conditions as in the Jacobi and Gauss-Seidel problems.) Determine the total number of iterations required with this optimal w (the initial guess does not count as an iteration, but every other guess does) and save this value in a variable called ans3. Save your final guess in a 103 x 1 column vector called ans4. To test the efficacy of this method, find the maximum error between your final answer and the true solution phi. That is, find ||ans4 - phi||_inf. Save your result in a variable named ans5. Poisson's Equation Consider the linear system A_n phi = rho, where A_n is an n x n matrix with 2's on the main diagonal, -1's directly above and below the main diagonal and 0's everywhere else. For example, A_5 = [ 2 -1 0 0 0; -1 2 -1 0 0; 0 -1 2 -1 0; 0 0 -1 2 -1; 0 0 0 -1 2]. This is a discretized version of Poisson's equation which appears very often in physical applications. We will discuss discretizations and differential equations, including the origin of the matrix A_n, later in the class. Construct the matrix A_103 in Matlab. (You should be able to do this in only a few lines with the help of the diag command. In particular, you should figure out what the commands diag(v), diag(v, 1) and diag(v, -1) do when v is a vector.) In addition, construct the 103 x 1 vector rho such that the jth entry of rho is defined according ot the formula rho_j = 2(1 - cos(37 pi / 104)) sin(37 pi j / 104). If you are particularly good with trigonometric identities, you can show that the exact solution to our problem is the 103 x 1 vector phi whose jth entry is defined according to the formula phi_j = sin(37 pi j / 104).

Sri K.

matlab-1-use-for-loop-to-create-a-n-x-n-matrix-m-where-each-element-is-either-1-or-0-no-two-adjacent-elements-are-the-same-and-m11-1-use-the-input-variable-n-and-name-the-function-mymatrix-w-32605

1) Use a 'for loop' to create an (n x n) matrix M where each element is either 1 or 0. No two adjacent elements are the same, and M(1,1) = 1. Use the input variable n and name the function myMatrix. Write the function in the correct format to be used to create a MATLAB function. 2) Create a function to output a one-dimensional double array M with n elements where the first three elements are 1, and each subsequent element is the sum of the previous three elements before it. Name the function myArray. Write the function in the correct format to be used to create a MATLAB function. Call the function in the correct format to output the array with 7 elements. 3) factorial n = n! = n * (n-1) * (n-2) * ... * 3 * 2 * 1 [For our purpose, you may assume n > 0]. nCr (n Combination r) is the number of ways r elements can be chosen from n elements where the order of choice does not matter. [For our purpose, assume r < n]. nCr = n! / (r! * (n-r)!). Write a function myCombination to calculate 'n Combination r' (i.e., nCr) by calling a subfunction myFactorial. Write the subfunction myFactorial to calculate the factorial of a number n, without using any built-in function like factorial(n) or prod(1:n), etc. Use a 'for loop' and elementary mathematical operations like multiplication, addition, subtraction, and division. [The stated elementary operations are just examples. You may not need all of them]. For myFactorial, use the output variable fact and the input variable n. For myCombination, use the output variable nCr and the input variables n and r. 4. Write a MATLAB script to output an animated plot of sin(x) versus x. In the same plot, produce the animated plot of cos(x) versus x. Use x going from -10 to 10 with 100 equidistant points. Sin(x) should be plotted in black right-pointing triangles. Cos(x) should be plotted in green circles. Include a legend for the plots to properly identify. 5. Write a MATLAB script using a 'while loop' to output all the integers n between 1 and 50 such that (n^3 - n^2) > 1000 and n is not divisible by 3. [If you want, you may display those values of n by correctly using the command disp(n) in your MATLAB script]. 6. Write a MATLAB function myNewArray in the correct format which takes as input a one-dimensional double array A with an even number of elements. It produces an output array out with half the number of elements as A. Each element of out is the sum of the corresponding element of A from the beginning of A and the corresponding element of A from the end of A. [example: A = [A1, A2, A3, A4, A5, A6], out = [A1+A6, A2+A5, A3+A4] and so on]

Sri K.

jacobi-methodplease-help-in-python-problem-3-consider-the-linear-system-an-where-an-is-an-n-n-matrix-with-2s-on-the-main-diagonal-1s-directly-above-and-below-the-main-diagonal-and-0s-everywh-85666

PROBLEM 3 Consider the linear system A_nϕ = ρ, where A_n is an n × n matrix with 2's on the main diagonal, -1's directly above and below the main diagonal and 0's everywhere else. For example, A_5 = ⎛ 2 -1 0 0 0 ⎞ ⎜-1 2 -1 0 0 ⎝ ⎜ 0 -1 2 -1 0 ⎝ ⎜ 0 0 -1 2 -1 ⎝ ⎝ 0 0 0 -1 2 ⎟ This is a discretized version of Poisson's equation d²ϕ(x)/dx² = ρ(x), which appears very often in physical applications. We will discuss discretizations and differential equations, including the origin of the matrix A_n, later in the class. (1) Setting up the matrix: (a) Construct the matrix A_114 in MATLAB/python. (You should be able to do this in only a few lines of code with the help of the diag or np.diag function. In particular, you should figure out what the commands diag(v), diag(v, 1) and diag(v, -1) do when v is a vector or 1D array.) Save a copy of this matrix in a variable named A9 (remember, in python you need to use A9 = A.copy()). (b) Now construct the right hand side vector ρ. This should be a 114 × 1 vector such that the jth entry of ρ is ρ_j = 2(1 - cos(53π/115))sin(53πj/115) Save a copy of this vector in a variable named A10 (remember, in python you need to use A10 = rho.copy()). (2) Jacobi method: (a) The Jacobi method for this problem can be written as ϕ_k = Mϕ_{k-1} + c, where M is a 114 × 114 matrix that we discussed in lecture. (Note that ϕ_k in this equation means the kᵗỐ guess for the vector ϕ and it is an entire vector. It does not mean the kth entry of ϕ). Use the Jacobi method to solve for ϕ. Your initialization should be a 114 × 1 vector of all ones, and you should use a tolerance of 10⁻⁵. That is, you should stop when ||ϕ_k - ϕ_{k-1}||∞ < 10⁻⁵ using the abs() and max() functions. Save a copy of your final iteration in a 114 × 1 column vector named A11. Save the total number of iterations required (including the initial iteration) in a variable named A12. (b) The true solution to the system of equations Aϕ = ρ is the 114 × 1 vector ϕ whose jth entry is defined according to the formula ϕ_j = sin(53πj/115). To test the efficacy of the Jacobi method on this problem, find the maximum error in absolute value between your final iteration and the true solution using the abs() and max() functions. Save your result in a variable named A13.

Akash M.


*

Recommended Textbooks

-
Elementary and Intermediate Algebra

Elementary and Intermediate Algebra

Alan S. Tussy, R. David Gustafson 5th Edition
achievement 1,568 solutions
Elementary and Intermediate Algebra

Elementary and Intermediate Algebra

Marvin L. Bittinger, David J. Ellenbogen,Barbara L. Johnson 4th Edition
achievement 1,606 solutions
Algebra and Trigonometry

Algebra and Trigonometry

James Stewart, Lothar Redlin, Saleem Watson 4th Edition
achievement 1,758 solutions

*

Transcript

-
00:01 Let's discuss this question.
00:01 So here using this graph of f shown in this figure, we need to evaluate the integral by interpreting its geometry.
00:09 So here evaluate.
00:13 So evaluation of line...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever