Functions and Scripts For this part you will need to write both a function and a
ID: 3673726 • Letter: F
Question
Functions and Scripts For this part you will need to write both a function and a script Write a function called areal that asks the user to enter two values height 1 and length1 Your function should then calculate and return the area and perimeter of a rectangle with the given height and length You should store the values calculated m variable-, perim1 and a1. Write a script called area2 that asks the user to enter two values height2 and Iength2. Your script should then calculate and print out the area and perimeter of a rectangle with the given height and length you should store the values calculated in variables perim2 and a2. Clear the command window in MATLAB and then run both your script and your function and call whos. Add a comment to your area2.m file describing which of the variables height1, height2. Length1, Iength2, perim1, perim2, a1, and a2 that you saw when you typed whos. Why were the variables you saw there? Why were others missing? What value is stored in ans? How did it get there? Turn in area1.m and area2.mExplanation / Answer
1.<html>
<head>
<title>Find the area and perimeter of the rectangle</title>
</head>
<body>
<script language="JavaScript">
function CalculateArea(){
var length1 =document.form1.txtRadius.value;
var height1 =document.form1.txtRadius1.value;
var a1=length1* height1;
document.write("The area of the rectangle is a1="+a1);
}
function CalculatePerimeter(){
var length1 =document.form1.txtRadius.value;
var height1 =document.form1.txtRadius1.value;
var perim1=(length1*2)* (height1*2);
document.write("The perimeter of the rectangle is perim1 "+perim1);
}
</script>
<form name=form1>
Enter the length and height of the rectangle
<input type="text" name="txtRadius" size=10><br>
<input type="text" name="txtRadius1" size=10>
<br>
<input type="button" value="Calculate"><br>
<input type="button" value="Calculate">
</form>
</script>
</body>
</html>
2.
<html>
<head>
<title>Find the area and perimeter of the rectangle</title>
</head>
<body>
<script language="JavaScript">
function CalculateArea(){
var length2 =document.form1.txtRadius.value;
var height2 =document.form1.txtRadius1.value;
var a1=length2* height2;
document.write("The area of the rectangle is a2="+a1);
}
function CalculatePerimeter(){
var length2 =document.form1.txtRadius.value;
var height2 =document.form1.txtRadius1.value;
var perim1=(length2*2)* (height2*2);
document.write("The perimeter of the rectangle is perim2 "+perim1);
}
</script>
<form name=form1>
Enter the length and height of the rectangle
<input type="text" name="txtRadius" size=10><br>
<input type="text" name="txtRadius1" size=10>
<br>
<input type="button" value="Calculate"><br>
<input type="button" value="Calculate">
</form>
</script>
</body>
</html>
3.To clear the command window we use cls.
when we run the script programs the in the MATLAB it only shows the one program willbe executed .
Here it shows only the one program output from the environment.
The first program shows what ever the variables content is entered in the promts that only is displayed in the environment.
That means the area and the perimeter of the first program values are executed but not the second program variables and the data.
when ever we execute the both scripts it only shows the first program outputs only that is area1 and calulateperimeter functions are executed.
the second program variable values are terminated .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.