For this assignment, you will write a script m-file called

hw2.m. There are multiple exercises in this assignment, be sure to

label your solution to each exercise with a comment. Some of the

exercises ask for additional m-files that will be called from within

hw1.m.

Problem 1:

In hw2.m create the following matrices:

16 4 3 0

A = 9 20 5 1

34 16 7 8

23 1 0 5

B = 9 8 16 7

34 12 3 2

In hw2.m, use A an B to create the following additional matrices:

C = the element in the 3rd row, 3rd column of A

D = the entire 4th column of A

E = rows 1 and 3 of B

F = a 6x4 matrix where the first three rows are the rows of A

and the second three rows are the rows of B

G = A(2:3,:) - in the comments for the problem explain what the lone

colon does when used this way

next make some changes to the entries in these matrices

- Make element (2,3) of E be 20

- Make row 1 of B all 0's

- Make column 3 of F be the numbers 0 through 5

Problem 2:

Create a function called cubic (in a file called cubic.m) that returns

the results of a*x^3 + b*x^2 + c*x +d. The function should accept two

inputs. The first input is a 1x4 vector called A where A contains the

values of a, b, c, and d. The second is the variable x.

From hw2.m test your cubic function on a number of inputs.

Problem 3:

From hw2.m prompt the user to enter a number x (use the input function

for this). Solve for y and z in terms of the inputed x. The

variables y and z are defined as follows:

y = x - 30 when 0 < x < 100

= 0.20*x + 800 when x > 100

= -50 otherwise

z = -1 when x < 0

= 0 when x = 0

= 1 when x > 0

Problem 4:

Although the accepted standard of measurement is the metric system,

many scientists still use non-standardized units in their

experiments. Thus it is very useful to have a function that can

convert all the measurements into the standardized metric system.

Create a function english_to_metric in (english_to_metric.m) that can

convert gallons to liters, pounds to kilograms, Fahrenheit to Celsius,

and yards to meters. Your function should take two inputs x and y. x

will be a flag that tells the function what you are trying to convert

to (let ‘L’ = convert to Liters, ‘Kg’ = convert to kilograms, ‘C’ =

convert to Celsius, and ‘M’ = convert to meters) and y is the value

that needs to be converted. Your function should have one output, the

converted value. Your function should display a message if the user

inputs a letter that is not one of the recognized flags and return the

empty matrix ( [] ).

Your function should give identical output as below:

>> z = english_to_metric('L', 64)

z=

242.2664

>> z = english_to_metric('Kg', 100)

z=

45.3593

>> z = english_to_metric('C', 32)

z=

0

>> z = english_to_metric('M', 1)

z=

0.9144

>> z = english_to_metric('D', 50)

Please input correct flag.

z=

[]

Give some examples of your function running in the hw2.m script file.

What you need to submit:

After you have successfully completed this assignment you will have a

number of files:

hw2.m

cubic.m

english_to_metric.m

Create a zip file containing a number of files.

Subject | Computer |

Due By (Pacific Time) | 11/26/2013 01:00 pm |

Tutor | Rating |
---|---|

pallavi Chat Now! |
out of 1971 reviews More.. |

amosmm Chat Now! |
out of 766 reviews More.. |

PhyzKyd Chat Now! |
out of 1164 reviews More.. |

rajdeep77 Chat Now! |
out of 721 reviews More.. |

sctys Chat Now! |
out of 1600 reviews More.. |

sharadgreen Chat Now! |
out of 770 reviews More.. |

topnotcher Chat Now! |
out of 766 reviews More.. |

XXXIAO Chat Now! |
out of 680 reviews More.. |