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
- Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw HillFunctions and Change: A Modeling Approach to Coll...AlgebraISBN:9781337111348Author:Bruce Crauder, Benny Evans, Alan NoellPublisher:Cengage LearningAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage
- College Algebra (MindTap Course List)AlgebraISBN:9781305652231Author:R. David Gustafson, Jeff HughesPublisher:Cengage LearningAlgebra and Trigonometry (MindTap Course List)AlgebraISBN:9781305071742Author:James Stewart, Lothar Redlin, Saleem WatsonPublisher:Cengage LearningAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell