Definition
For this question we have to write MATLAB code to detect a scalene triangle by reading in three numerical values representing the lengths of the three sides and printing “it’s a scalene” if the triangle is not an isosceles or equilateral triangle and the sum of any two side’s length is greater than the length of the other side.
Testing
On paper, or in a text file, write three new tests for the above program. As an example, three tests for this program might be.
inputs output
5 5 5 <no output>
2 1 2 <no output>
3 2 1 <no output>
3 4 5 “it’s a scalene”
Coding
If you are sharing a computer, swap a new group member to the terminal. Write a MATLAB script called q6.m that implements the definition above using at least if-statements.
Definition:
In this question we define code that reads in three positive numbers representing the lengths of the sides of a triangle and prints out a message saying “it’s equilateral” if all three sides are of equal length.
Testing:
On paper, or in a text file, write three new tests for the above program. As an example, two tests for this program might be.
inputs output
5 5 5 “it’s equilateral”
2 1 2 <no output>
If there is a group of x people in a room, what is the probability that two or more of them have the same birthday? It is possible to determine the answer to this question by simulation.
a) Make a getRandom function , then edit as follows to: Take as input n, which is the maximum random number that may be generated Return (output) a number in the range 1 to n Tip: Still use the round(rand()) construct, but this time, you are multiplying by n and adding 1. (note that you are NOT using the randi built-in function here!)
2 b) Write a new getRandomArray function : Take as input the number of people in a room (x) and the maximum number that can be used (n) Return an array of b numbers (i.e. the birthdays) Use the getRandom function to generate a random birthday for each person, from 1 to n Tip: initialise x and use a loop to generate the required number of elements and build the array.
Write a MATLAB code to solve the following problem.
The forced oscillations of a body of mass m on a spring of modulus k are
governed by the ODE
my" +cy' +ky = r
Find the steady-state solution for y(t), if m = 1 kg, c == 0.05g/sec and k =
25 g/sec. Where,
r(t) = {t + pi/2 -pi <= t <= 0; t - pi/2 0 <= t <= pi }
where, r(t) = r(t + 2pi).
Write a MATLAB code to calculate and plot the following problem.
Rectifier: Find the Fourier series of the function obtained by passing the
voltage v(t) = 10 sin(100xt)through a half-wave rectifier that clips the negative
half-waves.
The graph of a function
𝑓(𝑥) = 𝑝𝑥
4 + 𝑞𝑥
3 + 𝑟𝑥
2 + 𝑠𝑥 + 𝑡
passes through the points ( 2.5, 62 ) , ( 1.5, 7.2 ) , ( 0.5, 8.3) , ( -1, -3.7 ) and ( -3, -45.7) . Write
a program that determine the values of constants 𝑝, 𝑞, 𝑟, 𝑠,𝑡.
Write a program to find the acceleration of the object at a point ( 2, 3 ) using Matlab symbolic
tool box commands. The particle position function is following. [2]
𝑠(𝑡) = 2𝑡
4 − 7cos(𝑡) + 𝑒
−2𝑡
The curvilinear motion of a particle is defined by the following parametric equations
𝑥 = 52𝑡 − 9𝑡
2
, 𝑦 = 125 − 5𝑡
3
The velocity of a particle is defined by 𝑣 = √𝑣𝑥
2 + 𝑣𝑦
2. For time interval [0 6] make a first
plot that shows the position of the particle ( y vs x) and a second plot ( on the same figure
window) of the velocity of the particle as a function of time. In addition, using an asterisk
marker show the position of the particle ( in first plot ) at which its speed is maximum. For time
use a vector with spacing of 0.1s.
Write a MATLAB code to solve the following difference equations by z-transform and display the solutions by stem plots:
2) Suppose that the number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours?
Write a MATLAB code to solve the following difference equations by z-transform and display the solutions by stem plots:
3) A bank account gives an interest rate of 5% compounded monthly. If you invest initially Rs .1000 and add Rs. 10 every month. How much money do you have after 5 years?