![]() ![]() % Change the rate on the 8th year to 5.75%įor year = % ** increment the year from 1 to 10 ** % Calculate his resulting investment each year and after 10 years. % Sam gets paid compound interest at a rate defined at 5% per annum. While % ** num is not bigger than maxValue ** % Use a while- loop to print out the square of integers from 1 up to > Use array operations from Practical 3 to solve the problem in Exercise 1. Square = num^2 % this line prints the square % Use a for- loop to print out the square of integers from 1 up to %maxValue.įor num = % ** increment num from 1 to maxValue ** % Enter your name, student ID and the date here > Fill in the correspondent commands doing what required within **.**. If you comment out a line containing for, while or if-else, don’t forget to comment out the corresponding end statements. Tip: If you are having trouble finding an error, try commenting out a few lines to determine the line that is causing i. Run each cell separately and follow the instructions, making sure that you also add in the required code marked by starred lines. > Complete the exercises in the script M-file for this week. > What happens when x equals to zero or x is not zero? ![]() % This code assigns the value of x to zeroValue only % if x is zero If x What is wrong with the following code? Type it in MATLAB to check the error message. % This code assigns the value of x to negativeValue True if a is equal to 6 (note double equals sign) How many times will the starred line of the previous example be executed? What are starting point, increment (step) and ending point of this loop? S=0 % Initial assignment for sum to be able to Type in the following code and examine the output. While i Calculate the sum S of elements a i =√2i-1, i=1, 2. I=1 %we need to have a starting point to be able Now, let’s do the same by using while- loop Note: the command ‘ for i=1:1:10’ is equivalent to ‘ for i=1:10’.Note: the command ‘ for i=1:1:10’ does not create an array.The Syntax for for and while loops is as follows Else the hour of the day is not 6pm, print the statement “it is not dinner-time, it’s o’clock”. If the hour of the day is 6pm, print the statement “it is dinner-time, it’s o’clock”. In this case you do not know what will be your last number.Įxecutes a set of commands once, if a given condition is met, else- executes a set of commands, if the given condition is not met. In other words, while chronometer hand have not done a whole circle, keep counting. You are asked to count during one minute. CommandĮxecutes a set of commands repeatedly by incrementing a variable by a given step size until the set maximum is reached.įor each hour from 1pm to 12pm, print the statement “it is o’clock”.Įxecutes a set of commands if a condition after while is true. The following table shows the main types. MATLAB offers features to allow you to control the sequencing of commands by setting conditions. Use this word document as a template to prepare your responses for submission. Please submit your responses to the activities within this practical for formative feedback from your MATLAB eTutor. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |