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
Expert Solution & Answer
Check Mark
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.

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!
Students have asked these similar questions
ctor es ces If need help after the second attempt to this question, click Show Detailed Solution button below for formula and a similar problem. A researcher believes a new diet will have a positive impact on the health of adult lab mice but the effects on the weight of the mice are unknown. A sample of 10 mice was obtained and the mice were weighed before and after the diet treatment. Listed below are the measurement results: Click this button to reveal the data. Click again to collapse it. Mouse Before(g) After(g) Difference(g) 1 34.2 33.4 0.8 2 35 34.7 0.3 3 34.4 34.9 -0.5 35.9 34.4 1.5 5 33.2 32.8 0.4 6 35.8 34.5 1.3 7 35.4 35.6 -0.2 8 34.2 33.1 1.1 9 38.2 38.3 -0.1 10 34.8 33.9 0.9 Click this button to reveal the summary of data. Click again to collapse it. Before(g) After(g) Difference(g) Average Standard deviation 35.11 1.36 34.56 1.57 0.55 0.68 Click Download CSV to download csv file of data or copy/paste the data into Excel. After downloading the file, you may want to save it…
A food-frequency questionnaire is used to measure dietary intake. The respondent specifies the number of servings of various food items they consumed over the previous week. The dietary cholesterol is then quantified for each respondent. The researchers were interested in assessing if there was an association between dietary cholesterol intake and high blood pressure. In a large sample of individuals who had completed the questionnaire, 250 persons with a high dietary cholesterol intake (greater than 300 mg/day) were selected and 250 persons with a low dietary cholesterol intake (less than 300 mg/day) were selected. The 500 selected participants had their medical history taken and were classified as having normal or high blood pressure. The data are given here. Blood Pressure Dietary Cholesterol High Total Low High 159 91 250 Low 78 172 250 Total 237 263 500 Test 2: two-tailed test for comparing two independent proportions 1. Clearly state the null and alternative hypothesis 2.…
Test 1: Chi-Square test for independence Clearly state the null and alternative hypothesis Calculate the test statistic and p value. Show all your work for calculating the test statistic and probability statement for p-value. You may use MINITAB to get the final value of test statistic and p value and you must attach any MINITAB outputs) State the final conclusion at 5% significance level
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Big Ideas Math A Bridge To Success Algebra 1: Stu...
Algebra
ISBN:9781680331141
Author:HOUGHTON MIFFLIN HARCOURT
Publisher:Houghton Mifflin Harcourt
Text book image
Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill
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
Text book image
College Algebra
Algebra
ISBN:9781938168383
Author:Jay Abramson
Publisher:OpenStax
Text book image
Holt Mcdougal Larson Pre-algebra: Student Edition...
Algebra
ISBN:9780547587776
Author:HOLT MCDOUGAL
Publisher:HOLT MCDOUGAL
Text book image
Trigonometry (MindTap Course List)
Trigonometry
ISBN:9781337278461
Author:Ron Larson
Publisher:Cengage Learning
Finding Local Maxima and Minima by Differentiation; Author: Professor Dave Explains;https://www.youtube.com/watch?v=pvLj1s7SOtk;License: Standard YouTube License, CC-BY