In: Computer Science
Use MATLAB to create a program that answers the given problems:
Implement a function that will change the very first symbol of the given message to uppercase, and make all the other letters lowercase.
2. Implement a function that will compute the area of a triangle.
%1st
function readableMessage = parseMessage(unreadableMessage)
%%readableMessage = function(unreadableMessage)
%input: unreadableMessage=> 1xM character vector
%output: readableMessage => 1xM character vector
readableMessage =
[upper(unreadableMessage(1)),lower(unreadableMessage(2:end))];
end
%to run the function, type the command shown below, on the left side, in the command window
%2
function area = triangle_Area(a,b,c)
%area = triangleArea(a,b,c)
%this function calculates the area of a triangle by 2 methods
%1
%When base and height are known
%In this case, argument a is the base, b is the height.
%c should not be provided
%2
%when length of all 3 sides are known
%In this case,a,b,c are the 3 side lengths
if nargin==2
area=.5*a*b;
elseif nargin==3
s=(a+b+c)/2;
area=sqrt(a*(s-a)*(s-b)*(s-c));
else
error('Invalid number of arguments')
end
end