Buscar

Cálculos Matemáticos em Matlab

Prévia do material em texto

Fariha Newaz
Karina Ruiz Suarez
1. 
A. 
	Test Case
	Sample Data
	Expected Result
	Verified
	Babe Ruth (1920)
	Singles:73 Doubles:36 Triples:9 
Home runs:54 At bats:458
	0.847
	yes
	Ken Griffey, Jr. (1994)
	Singles:72 Doubles:24 Triples:4 
Home runs:40 At bats:433
	0.674
	yes
	 Mark McGuire (1998)
	Singles:61 Doubles:21 Triples:0 
Home runs:70 At bats: 509
	0.752
	yes
	Jackie Robinson
(1949)
	Singles: 137
Doubles: 38
Triples: 12
Home runs: 16
At bats: 593
	0.528
	yes
	Kris Bryant (2017)
	Singles: 91
Doubles: 38
Triples: 4
Home runs: 29
At bats: 549
	0.537
	yes
	Christian Yelich (2017)
	Singles: 114
Doubles: 36
Triples: 6
Home runs: 18
At bats: 602
	0.458
	yes
	Javy Baez (2018)
	Singles: 125
Doubles: 37
Triples: 9
Home runs: 33
At bats:559
	0.640
	yes
Matlab code:
promptSingles = 'Input singles';
singles = input(promptSingles);
promptDoubles = 'Input doubles';
doubles = input(promptDoubles);
promptTriples = 'Input triples';
triples = input(promptTriples);
promptHomeRuns = 'Input home runs';
homeRuns = input(promptHomeRuns);
promptAtBats = 'Input at bats';
atBats = input(promptAtBats);
sluggingPercent = (singles*1 + doubles*2 + triples*3 +homeRuns*4)/atBats;
disp(sprintf('The slugging percentage is %0.3f',sluggingPercent));
Run function:
>> percentcalculator
Input singles73
Input doubles36
Input triples9
Input home runs54
Input at bats458
The slugging percentage is 0.847
>> 
>> percentCalculator
Input singles72
Input doubles24
Input triples4
Input home runs40
Input at bats433
The slugging percentage is 0.674
>> percentCalculator
Input singles61
Input doubles21
Input triples0
Input home runs70
Input at bats509
The slugging percentage is 0.752
>> percentCalculator
Input singles137
Input doubles38
Input triples12
Input home runs16
Input at bats593
The slugging percentage is 0.528
>> percentCalculator
Input singles91
Input doubles38
Input triples4
Input home runs29
Input at bats549
The slugging percentage is 0.537
>> percentCalculator
Input singles114
Input doubles36
Input triples6
Input home runs18
Input at bats602
The slugging percentage is 0.458
>> percentCalculator
Input singles125
Input doubles37
Input triples9
Input home runs29
Input at bats549
The slugging percentage is 0.537
>> percentCalculator
Input singles114
Input doubles36
Input triples6
Input home runs33
Input at bats559
The slugging percentage is 0.640
B. When exercising it is important to keep your heart rate within a range of values called the target heart rate zone (THRZ). To calculate your THRZ you first need to calculate your "predicted maximal heart rate", subtract your age from 220. Then use the following formulas to determine the limits on your THRZ in beats per minute (bpm).
· THRZ Lower limit (bpm) = 60% of the predicted maximal heart rate 
· THRZ Upper limit (bpm) = 75% of the predicted maximal heart rate
· Write a MATLAB function called THRZ that takes one scalar argument, a person's age, and returns two values, the THRZ Lower limit and THRZ Upper limit.
· Also demonstrate calling your function with your age and saving the two returned values in the command window variables "lower" and "upper".
	Test Case
	Sample Data
	ExpectedResult 
	Verified?
	toddler 
	5 years old 
	Lower: 129 bpm
Upper: 161 bpm
	Y 
	teen 
	16 years old 
	Lower: 122 bpm
Upper: 153 bpm
	Y
	adult 
	33 years old 
	Lower: 112 bpm
Upper: 140 bpm
	Y
	old 
	78 years old 
	Lower: 85 bpm
Upper: 107 bpm
	Y 
Matlab Script:
age = input('what is your age?');
lower = round(.6*(220-age)); 
upper = round(.75*(220-age));
disp(strcat('your target heart rate zone is between', num2str(lower),'and',num2str(upper)))
Run Function:
>> THRZ
what is your age?5
your target heart rate zone is between129and161
>> THRZ
what is your age?16
your target heart rate zone is between122and153
>> THRZ
what is your age?33
your target heart rate zone is between112and140
>> THRZ
what is your age?78
your target heart rate zone is between85and107
Run Function w/ my age:
>> THRZ
what is your age?18
your target heart rate zone is between121and152
C. Write a Matlab script that prompts the user for the length of the side of a cube, and then determines the radius of a sphere that has the same surface area as that cube and then the radius of a sphere that has the same volume as that cube. Output both radii with messages. In your test table be sure to test a range of values and types of values.
· Create a test table and write an m-file script solve the problem. Make sure to format the output if necessary.Use your test table to test your script.
	Test Case
	Sample Data
	Expected Result
	Verified?
	Big length 
	700
	R1: 483.69
R2: 9049
	Y
	Middle length 
	 55
	R1:38.00435
R2: 199.30
	 Y
	Small length
	 4
	R1:2.76
R2:3.909
	 Y
	 No length 
	 0
	R1: 0
R2: 0
	 Y 
Matlab Script:
s=input('what is the length of a side of a cube?');
rS1=sqrt((6*s^2)/(4*pi));
rS2=sqrt((3*s^3)/(4*pi));
disp(strcat('the radius of the first sphere is',num2str(rS1),'and the radius of the second sphere is',num2str(rS2)))
Run Script: 
>> Radius
what is the length of a side of a cube?700
the radius of the first sphere is483.6918and the radius of the second sphere is9049.0452
>> Radius 
what is the length of a side of a cube?55
the radius of the first sphere is38.0044and the radius of the second sphere is199.2965
>> Radius
what is the length of a side of a cube?4
the radius of the first sphere is2.764and the radius of the second sphere is3.9088
>> Radius
what is the length of a side of a cube?0
the radius of the first sphere is0and the radius of the second sphere is0
D. Some private water wells produce only 1/3 of a gallon of water per minute. Each member of a family will use around 60 gallons of water per day. One way to avoid running out of water with these low-yield wells is to use a separate, above-ground holding tank. However, there is also a "natural" water holding tank in the casing (i.e. the cylindrical hole) of the well itself. The deeper the well, the more water that will be stored that can be pumped out for household use. But water will not fill the entire depth of the well, in practice the static water level will generally be 50 feet or more below the ground surface.
We need a function "tankSize" that will return the minimum size of the separate, above-ground holding tank so there will always be enough water in the well and the tank for one day's use. The three arguments to the function should be:
· The radius of the well casing in inches (usually 2-6 inches).
· The total depth of the well in feet (usually 50-250 feet).
· The number of family members.
Also demonstrate calling your function and saving the return value in the identifier myTank.
What does it mean if the function returns a negative number?
	Test Case
	Sample Data
	Expected Result
	Verified?
	Small Radius
Small Depth
Small Family
	Radius: 0.17 ft
Depth: 50 ft
Family: 2
	120 gallons
	yes
	Large Radius
Large Depth 
Large Family
	Radius: 0.5 ft
Depth: 250 ft
Family: 6
	202.9 gallons
	yes
	Medium Radius
Small Depth
Large Family
	Radius: 0.25 ft
Depth: 55 ft
Family: 8
	479.1 gallons
	yes
	Small Radius
Medium Depth
Small Family
	Radius: 0.18 ft
Depth: 150 ft
Family: 3
	169.8 gallons
	yes
Function:
function [ tankSize ] = myTank(radiusWell, depthWell, familyMembers )
%We need a function named “tankSize” that will return the minimum size of the seperate, above-ground holding tank so there will always be enough water in the well and the tank for one day’s use.
% It takes three arguments which includes the radius of the well, depth of well, and %number of family members.
tankSize = round((60*familyMembers)-(((pi)*radiusWell^2)*(depthWell-50)),1);
End
Command Window:
>> myTank(0.17, 50, 2)
ans =
 120
>> myTank(0.5, 250, 6)
ans =
 202.9000
>> myTank(0.25, 55, 8)
ans =
 479
>> myTank(0.18, 150,3)
ans =
 169.8000
If the function returns a negative numberthen it means that the family needs a tank in order to have enough water in the day.

Continue navegando