CS 104 - Lab 3 - Gavin Coffer

pdf

School

Illinois Institute Of Technology *

*We aren’t endorsed by this school

Course

104

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

3

Uploaded by MegaWalrusMaster672

Report
Lab 3 Objectives : Continue suing MatLab to calculate solutions to problems Use format to produce appropriate output Use disp and sprintf to display appropriate output Use input to prompt for information and save the response in a variable 1. Declare a variable x and set it to 10. Declare a second variable y and set it to 3. Perform the following operations and verify the results : a. U = x + y b. V = xy c. W = x/y d. Z = sin x e. R = 8 sin y f. S = 5 sin(2y) x = 10 y = 3 U = x + y V = x * y W = x / y Z = sind(x) R = 8 * sind(y) S = 5 * sind(2 * y) 2. Set x to 2 and y to 5. Computer the following : a. yx^3 -------- x – y b. 3x ---- 2y c. 3/2xy d. x^5 ------- x^5 – 1
x = 2 y = 5 (y * x^3) / (x - y) (3 * x) / (2 * y) 3 / (2 * x * y) (x^5) / (x^5 - 1) 3. Set x to 3 and y to 4. Calculate the following : a. 1 (1 – -- ) ^ -1 x^5 b. 3πx^2 c. 3y ------------- 4x – 8 d. 4(y-5) -------------- 3x – 6 x = 3 y = 4 (1 - (1 / x^5))^-1 3 * pi * x^2 (3 * y) / (4 * x - 8) (4 * (y - 5)) / (3 * x - 6) 4. Use the MatLab help command to find information about : cosine, cos, :, *, plot, and label. help cosine help cos help : help * help plot help label 5. Use the MatLab help command to find out what happens if you give a negative argument to sqrt(). help sqrt result = sqrt(-9)
6. Use the format command to set the number of decimal places for output to 16. Display the value of π. Use the format command to set the number of decimal places for output to 4. Display π. . Use the format command to set the number of decimal places for currency. Display π. Set a variable multPi to π times 1000. . Use the format command to set the number of decimal places for scientific notation. Display multPi format long; disp(pi); format short; disp(pi); format bank; disp(pi); multPi = pi * 1000; format short e; disp(multPi); 7. Use the disp command to display the value of multPi (from above). Use the disp command to display the string ‘Hello World’. disp(multPi); disp("Hello World"); 8. Use the sprintf command to store following string in the variable stringMultPi : “The value of multPi is : <value of multPi with minimum field of 10 and 2 decimal places>”. Display stringMultPi. stringMultPi = sprintf('The value of multPi is: %.2f', multPi); disp(stringMultPi); 9. Use the input command to prompt the User for their age and store their age in the variable userAge. Display userAge. Display the string “Your age is : <whatever age they entered>”. userAge = input('Enter your age: ', 's'); disp(['Your age is: ' userAge]); 10. Use the input command to prompt the User for their favorite color. Store the color in the variable favColor. Display the message “Your favorite color is : <whatever color they entered>” favColor = input('Enter your favorite color: ', 's'); disp(['Your favorite color is: ' favColor]);
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