HW CH1 Prob 1.1

docx

School

Ocean County College *

*We aren’t endorsed by this school

Course

124

Subject

Chemistry

Date

Feb 20, 2024

Type

docx

Pages

5

Uploaded by cnw124

Report
Cassidy Wojcik 2/11/21 HW CH1 Prob 1.1 Exercise 1.1: Error messages Save a copy of the program ball.m and confirm that the copy runs as the original. You are now supposed to introduce errors in the code, one by one. For each error introduced, save and run the program, and comment how well Matlab’s response corresponds to the actual error. When you are finished with one error, re-set the program to correct behavior (and check that it works!) before moving on to the next error. a) Insert the word hello on the empty line above the assignment to v0. b) Remove the % sign in front of the comment initial velocity. c) Remove the = sign in the assignment to v0. d) Change the symbol ^ into **. e) Change the calculation of y to y = v0*t. f) Write x on the line just above where y is calculated. g) Change the statement y = v0*t - 0.5*g*t^2 into y = v0*t - 0.5*g*t^2;. That is, insert a semicolon at the end. Filename: testing_ball.m. Part A The error produced is “unrecognized function or variable ‘hello’.” When the program reads hello it does not know what to do with it because there is no command to go along with the word “hello”.
Part B The error produced by removing the percent sign is “unrecognized function or variable ‘Initial’”. The error highlights the word “initial” because it is the first word in the sentence. Just like the hello error, the program does not know what to do because there is no command to accompany the word “initial”. If velocity were the first word the error message would highlight the word “velocity. Part C
The error produced by removing the equals sign is “unrecognized function or variable ‘v0’”. Like parts A and B the program does not know what to do when it reaches line 4 and reads v0. By removing the equals sign there is no link between v0 and 5. Part D The error produced by changing ^ to ** is “Invalid use of operator”. There is no command in MATLAB that is represented by **. The error tells you which line the operator is on so the programmer can pick a functional operator. Part E
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The error produced during this run is “check for missing or extra characters”. The error is referring to the period at the end of line 7. A period can only work if there are more commands following. Part F The error produced by adding an x is “unrecognized function or variable ‘x’”. When the program reaches line 7 it displays an error because it does not recognize the command “x”. The letter “x” is not being associated with anything so, the program cannot move on. Part G
Adding a semicolon to the end of the equation, does not produce an error, but it also does not display an answer. The semicolon tells the program to store the answer to the equation but not to display it in the command window. When the semicolon is removed the answer will be displayed.