A5soln_ENGR215_F08

A5soln_ENGR215_F08 - elseif (k > 25) got = got +...

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

View Full Document Right Arrow Icon
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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: elseif (k &gt; 25) got = got + 100 * k; shares = shares - 100; end end got = 100*sum(price.*(price&gt;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

This document was uploaded on 10/07/2008.

Page1 / 2

A5soln_ENGR215_F08 - elseif (k &amp;amp;gt; 25) got = got +...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online