{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

A5soln_ENGR215_F08

# A5soln_ENGR215_F08 - elseif(k> 25 got = got 100 k shares...

This preview shows pages 1–2. Sign up to view the full content.

Engineering ENGR 215 College of San Mateo L. Demsetz Solutions to Assignment 5: Programming 1. Use MATLAB as described in Problems 1, 3, and 12 (page 188-191). 2. Write a MATLAB function to solve Problem 10 on page 190. Version 1 (using matlab array inequalities) function [paid got shares increase ] = stocks(price) paid = 100*sum(price.*(price<20)) got = 100*sum(price.*(price>25)) shares_change = 100*(sum(price<20)-sum(price>25)); shares = 1000 + shares_change; increase = price(length(price))*shares - price(1)*1000 - paid + got; Version 2 (using loops) function [paid got shares increase ] = stocks(price) shares = 1000; paid = 0; got = 0; increase = 0; for k = price if (k < 20) paid = paid + 100 * k; shares = shares + 100;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: elseif (k > 25) got = got + 100 * k; shares = shares - 100; end end got = 100*sum(price.*(price>25)) increase = price(length(price))*shares - price(1)*1000 - paid + got; Paid = 7300 Got = 5600 Shares = 1200 Increase = 14100 (if you just used the difference in share price, as in the text, increase = 15800) Engineering ENGR 215 College of San Mateo L. Demsetz 3. Write and test the program described in Problem 16 on page 191 4. Write and test the program described in Problem 30 on page 197. Use at least one while loop in your program. Submit your code as A5P4.m (with appropriate comments). Paste as comments at the end of the file evidence that you have tested the code thoroughly....
View Full Document

{[ snackBarMessage ]}