Description
Q1. Write a function that accepts a general row vector X as an input and generates a row vector
P such that P contains all of the positive elements of X.
Q2. Write a function that determines y for a given input x. Assume that π₯ is a scalar (as opposed
to being a vector or a matrix).
π¦ π₯ = β0.2π₯( + 7π₯+ π-..(/
Q3. Modify the function above such that the input π₯ can be a 2×2 matrix.
Q4. Write a function that uses the switch β case statement (refer to pg.189-192 in the textbook).
The function takes a vector of strings in a structure (see assign5.m to see how this is done) and a
number π₯ as input. Each string is the case condition which specifies the type of operation to be
performed on βxβ. The two cases for mathematical operations are βinvertβ and βroot2β. The
function produces a numeric output for a given numeric value of π₯ and the condition π . If π is
anything other than βinvertβ or βroot2β, the function sets the output equal to 0. Place the results
in a row vector corresponding to operations as listed in the structure π i.e. for the list of
operations βinvertβ,βroot2β,βnoneβ and x=0.5 the answer will be [2.0000 0.7071 0].
ENEL101 Assignment 5 Page 2 of 3
Q5. Write a function that takes the coefficients π, π, π of a quadratic equation of the form ππ₯+ +
ππ₯ + π = 0 as inputs and calculates the discriminant π· = π+ β 4ππ. Then,
If π· > 0 the program sets ππ’πππππ‘ = 2.
If π· < 0 the program sets ππ’πππππ‘ = 0.
If π· = 0 the program sets ππ’πππππ‘ = 1.
Q6. Fibonacci numbers are the numbers in a sequence in which the first two elements are 0 and
1, and the value of each subsequent element is the sum of the previous two elements as
0,1,1,2,3,5,8,13, β¦. Write a function that takes an integer π > 2 as input and stores the first π
Fibonacci numbers in a column vector. You do not need to check for the condition of π > 2.
Q7. Write a function that finds the fifth root of input P using Newtonβs method, applying the
recursive formula
π₯EFG = π₯E β π₯E
H β π
5 π₯E
J
For the first value use π₯G = π. Continue with the recursive formula until the estimated relative
error πΈ < 0.00001 where
πΈ = π₯EFG β π₯E
π₯E
The function must output a 1×2 vector, with the first element being the answer (the fifth root)
and the second element being the number of iterations that were needed.
Q8. Given a point π₯. = 0.25 and function π π₯ = π₯+π/ approximate the functionβs derivative
at π₯. using the four-point difference formula
π π π₯
π π₯ = π π₯. β 2β β π π₯. β β + π π₯. + β β π(π₯. + 2β)
12 β
using β = /Q
G. (β must be a small number relative to π₯.). The function must output a 1×3 vector,
the first element being the numerator, the second the denominator, and the third the resulting
approximation.

