Concept explainers
To write:
A
Answer to Problem 6.1P
Solution:
The function file is,
% MATLAB code to calculates and returns the perimeter and area of a rectangle.
%Function file.
function [perimeter, Area] = perimarea(len, Wid)
%put the input arguments as length and width and get the perimeter and area
%by using the function perimarea.
perimeter = 2*(len+Wid);
%define the variable perimeter.
Area = len*Wid;
%define the variable area.
end
% end of function
%The script file should be placed in the same folder.
Explanation of Solution
The formula for the area of the rectangle is given as,
Here, the length of the rectangle is
Substitute 10 for
The formula for the perimeter of the rectangle is given as,
Substitute 10 for
MATLAB Code:
clc
clear all
close all
% MATLAB code to calculates and returns the perimeter and area of a rectangle.
%Function file.
function [perimeter, Area] = perimarea(len, Wid)
%put the input arguments as length and width and get the perimeter and area
%by using the function perimarea.
perimeter = 2*(len+Wid);
%define the variable perimeter.
Area = len*Wid;
%define the variable area.
end
% end of function
%The script file should be placed in the same folder.
Save the MATLAB script with name, perimarea.m in the current folder. Execute the function by typing the function name at the command window to generate output.
Result:
The result is,
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- A Norman window has the shape of a rectangle surmounted by a semicircle. Suppose a Norman window is to have a perimeter of 28 ft. Find a function in the variable giving the area of the window.arrow_forwardWrite the functions in standard form given the following conditions x - intercepts 1 and 9arrow_forwardFind the values for the variables and show workarrow_forward
- MATLAB: An Introduction with ApplicationsStatisticsISBN:9781119256830Author:Amos GilatPublisher:John Wiley & Sons IncProbability and Statistics for Engineering and th...StatisticsISBN:9781305251809Author:Jay L. DevorePublisher:Cengage LearningStatistics for The Behavioral Sciences (MindTap C...StatisticsISBN:9781305504912Author:Frederick J Gravetter, Larry B. WallnauPublisher:Cengage Learning
- Elementary Statistics: Picturing the World (7th E...StatisticsISBN:9780134683416Author:Ron Larson, Betsy FarberPublisher:PEARSONThe Basic Practice of StatisticsStatisticsISBN:9781319042578Author:David S. Moore, William I. Notz, Michael A. FlignerPublisher:W. H. FreemanIntroduction to the Practice of StatisticsStatisticsISBN:9781319013387Author:David S. Moore, George P. McCabe, Bruce A. CraigPublisher:W. H. Freeman