![]() ![]() To find the first time we can just feed the first value of higher15 into the t vector. So we can use the higher15 vector to select the corresponding times of those h values that were bigger than 15, such as t_higher15 = t(higher15) But this gives us a whole vector of times! We can do better than that. We want to know what times those were at. Since we'll need to use these numbers again, lets save them in another vector, like so: higher15 = find(h>15) (As usual, test the new line in your script without the semicolon, then add it to suppress further output.) What this operation gives us is the cell numbers where the height vector had values >= 15. In matlab we can do this by using the relational operators on the price vector. We want to buy shares when the price is low, and sell when they are high. The problem describes a trading strategy. Then you can go back and add a' after it so it does not print out anymore when you run the script. Save, then run the script and verify it looks good. Try typing it into your script without a semicolon. Start by entering a set of comments at the top of your program, such as the following: % buySell.m A script to determine the result of a trading strategy % Your Name % Assignment 7 problem 1 You'll then want to define the price vector in your script, just as it is written in the problem statement above. Use MATLAB to compute (a) the amount you spent in buying shares, (b) the amount you received from the sale of shares, (c) the total number of shares you own after the 10th day, and (d) the net increase in the worth of your portfolio. The price, in dollars, of a certain stock over a 10-day period is given in the following array price = [19, 18, 22, 21, 25, 19, 17, 21, 27, 291 Suppose you owned 1000 shares at the start of the 10-day period, and you bought 100 shares every day the price was below $20 and sold 100 shares every day the price was above $25. 1) RELATIONAL OPERATORS Create a script file called buySell.m, where we will solve the following problem: 13. Don't forget to include your name, the date, etc. Each of your m-files should include appropriate comments to identify the problem and to describe your calculation process. Point MATLAB/Freemat to this folder and create a separate m-file for each problem below. ![]() ENGR V14 Assignment 7 Selection Structures Create a folder called assignment7.
0 Comments
Leave a Reply. |