Welcome To Home of Information

Write a MATLAB function that will accept the values a, b and c as inputs and return the value of A as output.

Posted in
No comments
Saturday, August 2, 2014 By Anonymous


The area, A, of a triangle with sides of length a, b and c is given by

A=sqrt (s(s -a)(s -b)(s-c))

where s =(a+b+c) / 2 .

Write a MATLAB function that will accept the values a, b and c as inputs and return the value of A as output.

a) You have to take input from the user for a,b and c.

b) The first line of the file must have the format:

function [list of outputs] = function name(list of inputs)

c) Document the function. That is, describe briefly the purpose of the function and how it can be used. These lines should be preceded by % which signify that they are comment lines that will be ignored when the function is evaluated.

d) What changes are required, if we want to return the value of ‘s’ too from this function.


 

Solution:
funtion Question7()
    SideA = input('Enter value for side A of a Triangle: ');        %getting input
    SideB = input('Enter Value for side B of a Triangle: ');           %getting input
    SideC = input(‘ Enter Value for side C of a Triangle: ');            %getting input
   
    Area = FindArea(SideA, sideB,SideC);   %findig Area
   
    FPRINTF('Area of Triangles with sides %.2f, %.2f, %.2f is %.2f \n', SideA, SideB, SideC, Area);
end
Function[Argument Area ] = FindArea( MA, MB, MC )
    S = (MA + MB + MC) / 2;    %Using formula
   
    Argument_Area =  sqrt(S * (S-MA) * (S-MB) * (S-MC));
end         


Related posts

0 comments:

About the Author

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque volutpat volutpat nibh nec posuere. Donec auctor arcut pretium consequat.

Proudly Powered by Blogger.