MATLAB: A Practical Introduction to Programming and Problem Solving
MATLAB: A Practical Introduction to Programming and Problem Solving
5th Edition
ISBN: 9780128154793
Author: Stormy Attaway Ph.D. Boston University
Publisher: Elsevier Science
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 6, Problem 6.1P
To determine

To write:

A function perimarea that calculates and returns the perimeter, area of rectangle and pass the length and width of the rectangle as input arguments.

Expert Solution & Answer
Check Mark

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,

Area=l×b

Here, the length of the rectangle is l and width is b.

Substitute 10 for l and 5 for b in the above formula.

Area=10×5=50

The formula for the perimeter of the rectangle is given as,

perimeter=2(l+b)

Substitute 10 for l and 5 for b in the above formula.

perimeter=2(10+5)=30

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,

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 6, Problem 6.1P

Therefore, the result is stated above.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Knowledge Booster
Background pattern image
Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, statistics and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill
Text book image
Functions and Change: A Modeling Approach to Coll...
Algebra
ISBN:9781337111348
Author:Bruce Crauder, Benny Evans, Alan Noell
Publisher:Cengage Learning
Text book image
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Text book image
College Algebra (MindTap Course List)
Algebra
ISBN:9781305652231
Author:R. David Gustafson, Jeff Hughes
Publisher:Cengage Learning
Text book image
Algebra and Trigonometry (MindTap Course List)
Algebra
ISBN:9781305071742
Author:James Stewart, Lothar Redlin, Saleem Watson
Publisher:Cengage Learning
Text book image
Algebra: Structure And Method, Book 1
Algebra
ISBN:9780395977224
Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. Cole
Publisher:McDougal Littell
Finding Local Maxima and Minima by Differentiation; Author: Professor Dave Explains;https://www.youtube.com/watch?v=pvLj1s7SOtk;License: Standard YouTube License, CC-BY