Python script full of errors

Problem Python Download this Python script. This Python script is full of syntax, runtime, and semantic errors. Please identify and correct these errors, such that code becomes fully executable and outputs the following message on the screen when running from...

Python dictionary of class members

Problem Python The following is the name list of all people in a hypothetical class. Christian-Andrew Bagby-wright Matthew Chrysler Niyousha Davachi Pauline Dredger Marcos Guillen Lauren Kuffel Shashank Kumbhare Hany Mahdy Sarah Moorman Andrew Myers Joshua Osborne Rebecca Proni Amir...

Python script call from the Bash command line

Problem Python Write a Python script that is directly executable from the Git Bash command line, without any need to invoke python interpreter. The script should produce exactly the following output, including line breaks and separations. Each part of the...

Impact of machine precision on numerical computation

Problem MATLAB Consider the following code named epsError.m, eps = 1.0; while 1.0 ~= 1.0 + eps disp(num2str(eps)); eps = eps / 2.0; end disp(['final eps:', num2str(eps)]); Explain what the code is doing. Run the code and observe the output....

Converting polar and Cartesian vector representations using functions and structures

Problem A vector is a mathematical quantity that has both magnitude and direction. A 2-dimensional vector can be represented as a displacement along $x$ and $y$ axes in rectangular (Cartesian) coordinates or, by a distance $r$ and an angle $\phi$...

Operator precedence

Problem Operator Precedence. Think about what the results would be for the following expressions, and then type them into the terminal to verify your answers. Briefly explain the results for each one. >> 1\2 >> 1/2 >> int8(1/2) >> int8(1/3)...

Check if number is even in one line function definition

Problem Write a one-line function is_even() that returns True is the input value to the function is an even number, and False otherwise. For example, is_even(3) False

Getting the boundary of objects in images

Problem Consider this MATLAB data file data3D.mat which contains a 3-dimensional $41\times 61\times 16$ matrix of the brain of a rat. Write a MATLAB script that creates and saves a graph of all $X-Y$ information for the 16 slices along...

Monte Carlo sampling of distribution functions

Problem Suppose that you wanted to generate points whose distribution follows the blue curve in the following curve, whose mathematical formulation is known (in the case here, the function is just the sum of two Gaussian distributions). Now, one way...

Monte Carlo approximation of the number Pi

Problem Suppose we did not know the value of $\pi$ and we wanted to estimate its value using Monte Carlo methods. One practical approach is to draw a square of unit side, with its diagonal opposite corners extending from the...

Modifying the index of a for-loop

Problem Python Consider the following list, numbers = list(range(10)) print(numbers) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Now run the following code, given the above list. Explain the weird behavior that you observe. for n in numbers:...

Matrix Initialization

Problem Provide three different methods of generating the matrix a, one method should use the diag() function, one should use the eye function, and one should use the zeros function. >> a a = 2 0 0 0 2 0...

MATLAB working directory

Problem Part 1 MATLAB Use MATLAB help to find out how you can create a new directory named mynewdir from the MATLAB command line. Then change the working directory the newly-created directory. Then create a MATLAB script in this directory...

Subplots in MATLAB

Problem MATLAB Consider this MATLAB data file data3D.mat which contains a 3-dimensional $41\times 61\times 16$ matrix of the brain of a rat. Write a MATLAB script that creates and saves a graph of all $X-Y$ information for the 16 slices...

MATLAB script full of errors

Problem MATLAB Download this code. This code is full syntax errors. Fix the errors and submit the corrected code with name matlab_script_full_of_errors_fixed.m in your folder for this HW. Explain in front of each corrected MATLAB statement, why the error occurred....

Getting the largest prime number smaller than the input value

Problem MATLAB Suppose you want to find the largest prime number that is smaller than a given input value by the user. Write a function named getLargestPrime that does so, using for-loop, break, and MATLAB’s intrinsic function isprime(). Here is...

Checking if an input is a prime number (via recursive function calls)?

Problem Write a logical (boolean) function named isPrime(n) that takes in an integer number n, and finds whether it is a Prime number or not. Example output is the following, isPrime(23) True isPrime(12) False Note that you do not need...

Integer overflow

Problem Overflow. What would happen if you went beyond the range for a particular type? For example, the largest integer that can be stored in int8 is 127, and the smallest integer is -128, so what would happen if we...

Implementing the Bell-shaped (Gaussian) function

Problem The bell-shaped Gaussian probability density function, \[f(x)=\frac{1}{\sqrt{2\pi}\sigma}\exp\bigg[ -\frac{1}{2}\bigg( \frac{x-\mu}{\sigma} \bigg)^2 \bigg]\] is one of the most widely used functions in science and technology. The parameters of the function (mu,sigma>0) are prescribed real numbers. Write a program for evaluating this...

Function generators

Problem Write a nested function that evaluates a polynomial of the form $y = ax^2+bx+c$. The host function genFunc() should be able to take a varying number of arguments using varargin with a maximum of 3 arguments (a,b,c) to initialize...