Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be writing a function in this assignment. So remember that a function i

ID: 3692571 • Letter: Y

Question

You will be writing a function in this assignment. So remember that a function is again written in an m-file, not your command window! Once you write your function in an m-file, save it in any folder you like (preferably somewhere in your U drive or your personal external storage device). But once you do that, remember to change the current directory in your MATLAB to that of the folder in which your function is saved. Otherwise MATLAB cannot find your function and you will get an error message. Changing the current directory in MATLAB was shown in your earlier labs as well as today's lab. You can change it by navigating through the folders, or use the cd function (for change directory), or copying and pasting the address of the folder in your current directory address bar at the top of your MATLAB desktop. i. Write a program to calculate the area of a triable, given the length of its three sides. You will use heron's formula to calculate this. Look up heron's formula or you will find it any basic algebra book or you can use the equation give below. If a, b, and c are the three sides of a triangle, then This must have three input arguments (for the three sides) and one output argument (the area). Next, write a separate script file, this will be your main program or calling program, which will call the function you just created in your step (i). In this main program, request the user to input the three sides of the triangle. Then call the function which you wrote to calculate the area, then print or display the area on the command window. Use a conditional statement (if statement) to check to make sure the user inputs a positive number for all three sides. Even if one of them is not positive, then print a message on the command window that says the user failed to put a positive side then stop the program. Also another check to make sure that sum of any two sides is greater than the third side. If not, then print a message on the command window that says the three sides input can't possibly form a triangle and then stop the program. Make sure to save this main program in the same folder where you have saved your function in step (i).

Explanation / Answer

fprintf(‘ Area of triangle ') sidea = input('Enter the first side of the triangle: '); sideb = input('Enter the secondside of the triangle: '); sidec = fprintf('Enter the thirdside of the triangle '); s = (sidea+sideb+sidec)/2 area= sqrt(s*(s-sidea)*(s-sideb)*(s-sidec)); fprintf('Area of the triangle is = %.2f ',area)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote