Question

In: Computer Science

Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...

Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter x value for triangle point A: 1 Enter y value for triangle point A: 2 Enter x value for triangle point B: 10 Enter y value for triangle point B: 1 Enter x value for triangle point C: 5 Enter y value for triangle point C: 8 Point A of the triangle is ( 1.00, 2.00 ) Point B of the triangle is ( 10.00, 1.00 ) Point C of the triangle is ( 5.00, 8.00 ) The centroid of the triangle is ( 5.33, 3.67 ) Enter x value for triangle point A: -5.5 Enter y value for triangle point A: -6.75 Enter x value for triangle point B: 11.1 Enter y value for triangle point B: -3.4 Enter x value for triangle point C: 1.275 Enter y value for triangle point C: 4.567 Point A of the triangle is ( -5.50, -6.75 ) Point B of the triangle is ( 11.10, -3.40 ) Point C of the triangle is ( 1.27, 4.57 ) The centroid of the triangle is ( 2.29, -1.86 )

Solutions

Expert Solution

MATLAB:


clc;close all;clear all;
xA=input('Enter x value for triangle point A:');
yA=input('Enter y value for triangle point A:');
xB=input('Enter x value for triangle point B:');
yB=input('Enter y value for triangle point B:');
xC=input('Enter x value for triangle point C:');
yC=input('Enter y value for triangle point C:');
fprintf('Point A of the triangle is (%4.2f ,%4.2f)\n',xA,yA)
fprintf('Point B of the triangle is (%4.2f ,%4.2f)\n',xB,yB)
fprintf('Point C of the triangle is (%4.2f ,%4.2f)\n',xC,yC)
xG=(xA+xB+xC)/3;
yG=(yA+yB+yC)/3;
fprintf('The centroid of the triangle is (%4.2f ,%4.2f)\n',xG,yG)

Command window:ouptut

Enter x value for triangle point A:1
Enter y value for triangle point A:2
Enter x value for triangle point B:10
Enter y value for triangle point B:1
Enter x value for triangle point C:5
Enter y value for triangle point C:8
Point A of the triangle is (1.00 ,2.00)
Point B of the triangle is (10.00 ,1.00)
Point C of the triangle is (5.00 ,8.00)
The centroid of the triangle is (5.33 ,3.67)
>>

Enter x value for triangle point A:-5.5
Enter y value for triangle point A:-6.75
Enter x value for triangle point B:11.1
Enter y value for triangle point B:-3.4
Enter x value for triangle point C:1.27
Enter y value for triangle point C:4.57
Point A of the triangle is (-5.50 ,-6.75)
Point B of the triangle is (11.10 ,-3.40)
Point C of the triangle is (1.27 ,4.57)
The centroid of the triangle is (2.29 ,-1.86)
>>


Related Solutions

Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval and stores it in a variable named Lbound - an upper-bound for the plot interval and stores it in a variable named Ubound, and - the number of points at which a function is to be evaluated to generate a plot of the function over the specified range and stores it in a variable named npoints. • Generates a plot of f(x) = x3...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered. (Using Matlab) and "while" function 2.   Write a program that prompts the User for if they would like to enter a real...
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower...
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower = 0.4 x_upper = 0.6 Es = 0.5*10^(2-n) n = 5
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
Write two scripts(must be titled “primeSumLoopS” and “primeSumCallS”) in MATLAB that prompts the user to enter...
Write two scripts(must be titled “primeSumLoopS” and “primeSumCallS”) in MATLAB that prompts the user to enter an integer x that 2< x <10000, then the program calculates and displays the sum of the all the prime numbers that are smaller than or equal to x. For example, if x is 11, then the output is 28, which is 2+3+5+7+11. Use two methods: the 1st script uses nested loop and the 2nd script calls another function, primeF.
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT