Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python/numpy In this problem, we will work on demonstrating the triangle inequality for norms using numpy and matplotlib. We are given two vectors u

Using Python/numpy

In this problem, we will work on demonstrating the triangle inequality for norms using numpy and matplotlib. We are given two vectors u and v as 1D numpy arrays.

In addition to regular pp-norms, we will use the "0.5-norm" below. By this we mean that you should use the expression for the pp-norm with p=0.5p=0.5. Note that this is not actually a norm.

Do the following:

Compute the 1-norm, 2-norm, 5-norm, and "0.5-norm" of the vector u+v. Store these norms in a 1D array sum_norm in the order of 1, 2, 5, and 0.5.

NOTE: Do NOT use numpy.linalg.norm to compute the norms.

Compute the 1-norm, 2-norm, 5-norm, and the "0.5-norm" of the vectors uu and vv. Store the sum u+v in a 1D array called norm_sum in the order of 1, 2, 5, and 0.5.

Next, we will plot what a ball looks like in each of these norms. Your code should produce the following four plots. (NOTE: Refer to the FAQ section for more information on how to construct these plots.)

a. Figure 1:

Draw a 2D ball (with respect to the 1-norm) with radius u1 and centered around the origin using 500 points.

(That is, all vectors ww, which make up the ball satisfy the equation w1=u1.)

Draw a 2D ball (with respect to the 1-norm) with radius v1 centered around the point uu.

Draw a 2D ball (with respect to the 1-norm) with radius u+v1 centered around origin.

Draw a 2D ball (with respect to the 1-norm) with radius u1+v1 centered around origin.

Using plt.arrow(), plot the vector u+v. Also plot the vector u with vector v such that the start of vector v is the end of vector u.

Pass length_includes_head=True to arrow() as a keyword argument, to prevent the arrows from "sticking out" across the boundary of the norm boundaries.

Save this plot's axes to fig_1 using plt.gca()

For example:

plt.figure() # ...code for the plot... fig_1 = plt.gca() 

b. Figure 2: Do everything in part (a) using the 2-norm.

Save this plot to fig_2

c. Figure 3: Do everything in part (a) using the 5-norm.

Save this plot to fig_3

d. Figure 4: Do everything in part (a) using the "0.5-norm".

Save this plot to fig_4

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

6. Vanguard

Answered: 1 week ago