Question

Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called...

Matlab Question (Matlab Grader)

Where indicated at the bottom of the script. write a function, called isright, that takes three inputs, a, b, and c, and determines whether they are could be the lengths of the sides of a right triangle; the output, y, will be set equal to the following:

i). -1 if at least one of the values is not positive. Also, only for this case, have the function print out an error message, which states "At least one of the inputs is not positive." (use the fprintf command instead of the error command).

ii). 1 if the three values could be the lengths of 3 sides of a right triangle; you will need the Pythagorean Theorem. (Note c doesn't necessarily have to be the hypotenuse with a and b the legs - they could potentially be any sides of the triangle).

iii). 0 if all three values are positive, butt they are not the right lengths.

Use one if statement that contains one elseif and one else in your code instead of individual if statements for each case, to minimize the number of logical comparisons.

note that the script is set up to call and test your function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Function satisfying all three cases is as follows:

function y = isright (a,b,c)    % here a,b,c are the inputs , y is the output
if ( (a<0) | (b<0) | (c<0) )   %test for negative values
    y= -1;                 %set y= -1

%test for any possible combimation that satisfies pythagorean theorem
elseif ((a*a == b*b+c*c) | ( b*b == c*c + a*a) | (c*c == a*a + b*b))
    y=1;                        %set y=1                                             
else
    y=0;                        %set y=0
end
end

The above function first checks for negative value if any of the three (a,b,c) is negative then it'll set y=-1,

elseif they satisfies Pythagorean theorem in any combination then it sets y=1,

otherwise set y=0

sample output:

Add a comment
Know the answer?
Add Answer to:
Matlab Question (Matlab Grader) Where indicated at the bottom of the script. write a function, called...
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 use Matlab to solve and show your full codes Write a script file Ask the...

    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...

  • Write a MATLAB script that reads in three floating point values from the user (a, b...

    Write a MATLAB script that reads in three floating point values from the user (a, b and c), which represent the lengths of three sides of a triangle. Then compute the area of the triangle according to the equation: Area s(s-a)(s- b)(s -e) where s is half of the sum of the three sides, or the average of a, b, & c Hint: look up MATLAB function that prompts read-in values from user

  • MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...

    MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3, that accepts two inputs: i) a row vector, called c, containing the coefficients of the polynomial, starting with the coefficient for the lowest degree term, which is the constant term. ii) a row vector, called x, which is the set of real numbers where the polynomial is to be evaluated. The output, y, will be a vector containing the values of the polynomial, evaluated...

  • MATLAB Question: Write a script for the problem pictured. Please send the script, not just the...

    MATLAB Question: Write a script for the problem pictured. Please send the script, not just the printout. Make sure your script allows you to input a value for n so when prompted, in the command window, user types n value. The n value should be the f_k if k ==1 .... Please also send print outs if you can. BELOW IS A SAMPLE ANSWER THAT DID NOT PUT THE INPUT SCRIPT NEEDED FOR THIS QUESTION TO BE CORRECT. YOU CAN...

  • Write a function called calc_crown_area that will receive pairs of lengths of radii as input arguments,...

    Write a function called calc_crown_area that will receive pairs of lengths of radii as input arguments, and will return the areas of the crowns. The function should work when: • the inputs are a pair of single values, i.e. one scalar for the inner radius and one scalar for the outer radius. In this case, the function will return one single output for the area. • the inputs are a pair of vectors, i.e. one vector of inner radii (R1)...

  • MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown...

    MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown below Write a script that does the following Define the following two anonymous functions and assign to the indicated Function Handles: 1. The function ThirdSide should accept the lengths of sides a and b as well as angle C in that order and use the Law of...

  • 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:...

  • Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three...

    Must be java code Project 2b: CalculatePerimeter You are to write code for the application CalculatePerimeter where the computer calculates and displays the perimeter of a triangle, provided the three double values entered from keyboard input represent a triangle. If they don't, the computer should display the fact that (at least, in the case of non-positive input) one of the values does not form a valid triangle What makes a valid triangle? All sides must be positive and the sum...

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial() B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees...

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