Question
Please use Matlab to solve and show your full codes
Write a script file Ask the user to enter sides of a triangle: a, b, c Check to see if the sides are all greater than 0 If they are: Use the function (triangle) that you created in your last homework problem (HW#5 problemttF) to calculate the area. command Display the results on the screen using fprintf write the results to disk using the fprintf command. If any of the sides triangle are zero or negative: display an error message. of the Print your m-file & the file written to disk. Please test & show results for sides 6, 8, 10
media%2F4f2%2F4f2b3379-ddf0-4e3f-a6e9-04
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% matlab code

function area = traingle(a,b,c)
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
end

a = input("Enter side1 of traingle: ");
b = input("Enter side2 of traingle: ");
c = input("Enter sidec of traingle: ");

if(a > 0 && b > 0 && c >0)
area = traingle(a,b,c);
fprintf("Area: %f\n",area);
else
disp("Invalid sides\n");
end

%{
output:
Enter side1 of traingle: 6
Enter side2 of traingle: 8
Enter sidec of traingle: 10
Area: 24.000000


Enter side1 of traingle: -1
Enter side2 of traingle: 3
Enter sidec of traingle: 2
Invalid sides
%}

Add a comment
Know the answer?
Add Answer to:
Please use Matlab to solve and show your full codes Write a script file Ask the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show in MATLAB code using if and else statements if necessary Write a program in a script ...

    Please show in MATLAB code using if and else statements if necessary Write a program in a script file that converts a quantity of energy given in units of either J (Joules), Btu, or (ft-lb) to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of power in the new units using the fprintf command....

  • Please answer 1c, use MATLAB, and paste your entire script in your answer so that I...

    Please answer 1c, use MATLAB, and paste your entire script in your answer so that I can copy and paste to see if it works. Problem #1 400g triangle square pentagon hexagon Figure 1 For a closed geometric figure composed of straight lines (Figure 1), the interior angles in the figure must add to (n-2)(180) where n is the number of sides. Required Tasks a) Write a script that prompts the user to select from one of the following shapes:...

  • Write a shell script to solve the following business problem. Create a file called whoislogin.out...

    Write a shell script to solve the following business problem. Create a file called whoislogin.out that contains the output of the who command, then append to the whois.out file, the output of the date and finger commands. Your script should prompt to pick any users from the list of users currently logged onto the system. Use the variable concept to search for the specific user from those displayed on the screen coming from the who is.out file created. Show a...

  • 1) Write a MATLAB script to prompt a user to input two numbers, then assess whether...

    1) Write a MATLAB script to prompt a user to input two numbers, then assess whether the two numbers are equal or not. If the two numbers are equal, display that they are equal in the Command Window. If they are not equal, display that they are not equal in the Command Window. 2) Write a MATLAB script that prompts the user to enter the day of the week using the input function. If the information the user enters is...

  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

  • Write a matlab script(using only matlab) for this. Write a script to solve the following problem:...

    Write a matlab script(using only matlab) for this. Write a script to solve the following problem: Ask the user for the length and the width of a rectangle. These need to be passed to a function. The function is to calculate and return the area and the perimeter of the rectangle. The area is the length times the width and the perimeter is 2 times the length and 2 times the width. Make sure to suppress all output from the...

  • MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print...

    MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print its equivalence in numerical scale. For example if the user enters A, then your function should print a message stating that the grade must be between 90 and 100. B is between 80 and 89, etc. Everything under 60 is F. Use the switch-case function. Use fprintf to display the results on the screen.

  • Problem 1: Use MATLAB to create a script file and publish a pdf file for the...

    Problem 1: Use MATLAB to create a script file and publish a pdf file for the problem: Given that MX = Y, for the following matrices determine X using both matrix inversion and Gaussian elimination methods 7 -2 4.67 5 7 6.5 -8 13 Y = 13 Display results in short engineering format. Submit the published pdf file. Problem 2: Use MATLAB to create a script file and publish a pdf file for the problem: Given that MX = Y,...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Create a single script (.m file) to complete this assignment. Unless directed otherwise, use meaningful variable...

    Create a single script (.m file) to complete this assignment. Unless directed otherwise, use meaningful variable names for each variable: do not use the default variable ans to store your results. For this assignment do not suppress your output with semi- colons (). Each problem (ie. Problem 1. Problem 2, and Problem 4) should be in a separate cell, using the cell mode feature of MATLAB; the subparts should all be contained in the same cell as the parent problem....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT