Computing the Fibonacci sequence via recursive function calls

Problem In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, that is characterized by the fact that every number after the first two is the sum of the two preceding ones: \[0,~1,~1,~2,~3,~5,~8,~13,~21,~34,~55,~89,~144,~\dots\]...

Computing the Fibonacci sequence via for-loop

MATLAB Problem Part MATLAB-A Consider the MATLAB function fib(). Modify this function using MATLAB’s built-in timeit() function such that fib() also returns the average runtime of the nested function getFib() inside fib(), right after giving the requested Fibonacci number. For...

Exception handling in the case of a simple projectile motion

Problem Python Consider the simplest program for evaluating the formula $y(t) = v_0t-\frac{1}{2}gt^2$, v0 = 3; g = 9.81; t = 0.6 y = v0*t - 0.5*g*t**2 print(y) (A) Write a program that takes in the above necessary input data...

Exception handling in the case of division by zero

Problem Python Consider the function Newton(), def Newton(f, dfdx, x, eps=1E-7, maxit=100): if not callable(f): raise TypeError( 'f is %s, should be function or class with __call__' % type(f) ) if not callable(dfdx): raise TypeError( 'dfdx is %s, should be...

Data transfer: Parsing Amino Acid data file

Problem Consider this data file. It contains information about the amino-acids in a protein called 1A2T. Each amino-acid in the protein is labeled by a single letter. There are 20 amin acid molecules in nature, and each has a total...

Command line input arguments summation via sum()

Problem Python Write a simple program named sum.py, that takes in an arbitrary-size list of input floats from the command-line, and prints out the sum of them on the terminal with the following message, $ python sum.py 1 2 1...

Command line input arguments summation via eval()

Problem Python Write a simple program named sum_via_eval.py that takes in an arbitrary-size list of input numbers from the command-line, and prints out the sum of them on the terminal which is computed using Python’s eval() function. The program output...

Calculating the size of a directory

Problem MATLAB The MATLAB function dir returns the contents of a specified directory. It returns the result in the form of a structure array with four fields, for example, s = dir s = 123x1 struct array with fields: name...

Branching, the Pythonic way

Problem Part A Change the first if statement in the following script to an equivalent one-line if-expression. Test the resulting new script, and make sure it behaves like the original, #!/usr/bin/env python abbr = input ("What is the three-letter abbreviation...