Starting from:
$35

$29

Homework 1 - MATLAB Basics Solution

Function Name: ​pythag

Inputs:
    1. (double)​length of side a

    2. (​double​) length of side b

Outputs:

    1. (double)​length of the hypotenuse, c

Function Description:

The Pythagorean theorem states that when a triangle has a right angle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. You probably already know this theorem from geometry class and have no doubt done used this formula countless times.
















a2 + b2 = c2

Given the side lengths of a right triangle, a and b, use MATLAB to determine the length of the hypotenuse. Now you'll never have to do this calculation yourself again!

Notes:

    • Round your answer to the hundredths place (second decimal place).

Hints:

    • The ​sqrt()​and ​round()​functions will prove useful.
Homework 1 - MATLAB Basics




Function Name: ​inscribe

Inputs:

    3. (double)​Side length of the square

Outputs:

    2. (double)​Area of the square not inscribed by the circle

Function Description:

When a circle is inscribed in a square, the diameter of the circle is equal to the side length of the square.





















Area of square = s2
Area of a circle = πr2

Use MATLAB to determine the area of the shaded region (the region not inscribed by the circle), given the side length of the square. The area formulas for a square and circle are given above.

Notes:

    • Do not approximate the value of π .

    • Round your answer to the hundredths place.

Hints:

    • Use ​pi​in MATLAB
Homework 1 - MATLAB Basics




Function Name: ​compound

Inputs:
    4. (double)​Future amount desired

    5. (​double​) Initial investment

    6. (double)​Annual interest rate (given as a positive decimal)

    7. (double)​Number of times the interest is compounded per year

Outputs:

    3. (double)​Number of years

Function Description:

You have just come into a small fortune. Lucky you! Instead of spending it all at once, you decide to invest your money so that it grows into an even larger desired amount. Use MATLAB to determine how many years it will take for your investment to grow to that amount based on a given annual interest rate and how many times the interest is compounded per year. The compound interest formula, which may prove useful, is given below.

A = P (1 + nr )nt

A = future value of investment

P = initial, principal investment

r = annual interest rate (decimal)

n = number of times the interest is compounded per year t = number of years the money is invested

Notes:

    • Round your answer up to the nearest year.

    • The amount desired will always be greater than the initial investment

Hints:

    • The ​log()​and ​ceil()​functions may prove useful.
Homework 1 - MATLAB Basics






Function Name:​​pizzaParty

Inputs:
    1. (double)​Number of party attendees

    2. (double)​Number of pizzas ordered

Outputs:
    1. (double)​Slices of pizza per person

    2. (double)​Slices of pizza left over

Function Description:

You decide to host a party and buy some pizzas for you and your friends. But, in order to be fair, every person should get the same number of slices of pizza. Any extra slices will be left over and saved for later.

You could try and calculate the pizza slice distribution yourself, but why bother when you can have MATLAB do all the hard work! Given the number of people at the party and the number of pizzas ordered, write a function that outputs how many slices of pizza each person should should receive, and how many slices of pizza will be left over.

For example, if there are 5 people at the party, and 2 pizzas were ordered, each person would get 3 slices, and 1 slice would be left over, so the first output would be 3 and the second output would be 1.

Notes:

    • Assume every pizza is cut into 8 slices.

    • You cannot have fraction slices.

Hints:

    • You may find the ​floor()​and/or ​mod()​functions useful.

More products