Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FOR Python Programming. My code was this and I got half of it wrong. import numpy as np def tanc(x): if isinstance(x,np.ndarray): arr = np.zeros(len(x))

FOR Python Programming.

image text in transcribedimage text in transcribed

My code was this and I got half of it wrong.

import numpy as np def tanc(x): if isinstance(x,np.ndarray): arr = np.zeros(len(x)) for index,val in enumerate(x): if val==0: arr[index] = 1 else: arr[index]= np.tan(val)/val return arr else: if x==0: return 1 else: return np.tan(x)/x import numpy as np def theta(t, omega, theta0=np.pi/6, Omega0=0): if isinstance(t,np.ndarray): th = np.zeros(len(t))

fi = -np.arctan((Omega0/omega)/theta0)

A = np.sqrt(((theta0**2)+((Omega0/omega)**2)))

for index,val in enumerate(t): th[index] = A * np.cos(omega*t[0] + fi)

return th

else:

fi = -np.arctan((Omega0/omega)/theta0)

A = np.sqrt(((theta0**2)+((Omega0/omega)**2))) return A * np.cos(omega*t + fi)

18.3 Functions This lab will be available until February 14th, 11:59 PM MST Solve the following problems. Use numpy and numpy arrays when possible. tanc function Define the function tan tanca : 1 as a Python function tanc(x) 1. Note that the function value at x = 0 is well defined lim tancx = 1. 20 Your function should take this into account. 2. Your function should behave like a numpy ufunc, i.e., it should be possible to use a numpy array as an argument and then it should return an array of the same size in which tanc() was applied element-wise. For example: >>> X = np.pi*np.array([0, 0.25, 1]) >>> tanc (X) array([ 1.0, 1.27323954e+00, -3.89817183e-17]) Note: Getting (2) to work is much harder than (1). Try to get (1) to work first (the initial tests only test scalar arguments). Note: Getting (2) to work is much harder than (1). Try to get (1) to work first (the initial tests only test scalar arguments). Harmonic pendulum trajectory The solution o(t) = A cos(wt+) A= 02 + 120/ = - arctan 00 for the harmonic pendulum depends on the frequency w and the initial conditions 69 = e(0) and No = N(0) = (0). Write a function theta() that does the following: 1. takes an array t of times as mandatory argument; 2. takes the mandatory argument omega to set the frequency: 3. returns an array of the same size as t in which e(t) was evaluated for each element in t; 4. contains a doc string that briefly explains the function and the arguments that it takes; 5. takes an optional argument thetal with default value 1/6; 6. takes an optional argument OmegaO with default value 0. 282326.1742132 LAB ACTIVITY 18.3.1: Functions 0/30 main.py Load default template... 1 # add your code 2 # (only function definitions are tested) 18.3 Functions This lab will be available until February 14th, 11:59 PM MST Solve the following problems. Use numpy and numpy arrays when possible. tanc function Define the function tan tanca : 1 as a Python function tanc(x) 1. Note that the function value at x = 0 is well defined lim tancx = 1. 20 Your function should take this into account. 2. Your function should behave like a numpy ufunc, i.e., it should be possible to use a numpy array as an argument and then it should return an array of the same size in which tanc() was applied element-wise. For example: >>> X = np.pi*np.array([0, 0.25, 1]) >>> tanc (X) array([ 1.0, 1.27323954e+00, -3.89817183e-17]) Note: Getting (2) to work is much harder than (1). Try to get (1) to work first (the initial tests only test scalar arguments). Note: Getting (2) to work is much harder than (1). Try to get (1) to work first (the initial tests only test scalar arguments). Harmonic pendulum trajectory The solution o(t) = A cos(wt+) A= 02 + 120/ = - arctan 00 for the harmonic pendulum depends on the frequency w and the initial conditions 69 = e(0) and No = N(0) = (0). Write a function theta() that does the following: 1. takes an array t of times as mandatory argument; 2. takes the mandatory argument omega to set the frequency: 3. returns an array of the same size as t in which e(t) was evaluated for each element in t; 4. contains a doc string that briefly explains the function and the arguments that it takes; 5. takes an optional argument thetal with default value 1/6; 6. takes an optional argument OmegaO with default value 0. 282326.1742132 LAB ACTIVITY 18.3.1: Functions 0/30 main.py Load default template... 1 # add your code 2 # (only function definitions are tested)

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

How is an NSF check accounted for in the accounting records?

Answered: 1 week ago

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago