CHAPTER 3
PROBLEM 1:
For the function Calculate the value off for the following values of x using element-by-
element operations:
SOLUTION:
clc, clear, close all
%Values of x
x=1:7
x = 1x7
6
%Values of y
y=x.’2-x./(x+3)
y = 1 x7
0.7500 3.6000 8.5000 15.4286 24.3750 35.3333 48.3000
PROBLEM 2:
For the function calculate the value ofy for the following values off using element-by-element
operations:
SOLUTION:
clc, clear, close all
%Values of x
x=1.5:0.5:4
x = 1x6
1.5000 2.0000 2.5000 3.0000 3.5000 4.0000
%Values of y
y=x.’4.*exp(-x)
y = 1x6
1.1296 2.1654 3.2064 4.0328 4.5315 4.6888
PROBLEM 3:
For the function calculate the value of y for the following values of x using
element-by-element operations:
SOLUTION:
clc, clear, close all
%Values of x
x=-2:0.5:2
x = 1 x9
-2.0000 -1.5000 -1.0000 -0.5000 0 0.5000 1.0000 1.5000 2.0000
%Solve for y
y=(x+x.*sqrt(x+3)).*(1+2*x.’2)-x.’3
y = 1x9
-28.0000 -14.9791 -6.2426 -1.8109 0 2.0281 8.0000 22.3759 50.2492
PROBLEM 4:
For the function calculate the value off for the following values of x using element-by-
element operations:
SOLUTION:
clc, clear, close all
%Values of x
x=15:10:65
15 25 35 45 55 65
%Solve for y
y=(4*sind(x)+6)./(cosd(x).’2+sind(x)).’2
y = 1x6
4.9528 4.9694 5.3546 6.0589 7.0372 8.1775
PROBLEM 5:
The radius, of a sphere can be calculated from its volume, by:
The surface area of a sphere, is given by:
SOLUTION:
clc, clear, close all
%Values of V
V=4000:-500:1000;
%Define r
r=(3/(4*pi)*V).’(1/3);
%Define S
S=4*pi*r.’2;
Result(:,1)=round(r*10)/10;
Result(:,2)=V;
%Define Result
Result(:,3)=round(S*10)/10
Result = 7x3
103 x
0.0098 4.0000 1.2186
0.0094 3.5000 1.1148
0.0089 3.0000 1.0059
0.0084 2.5000 0.8908
0.0078 2.0000 0.7677
0.0071 1.5000 0.6337
0.0062 1.0000 0.4836
CHAPTER 4
PROBLEM 1:
Body mass index (BMI) of a person is a measure of body fat based on height
and weight. In U.S. customary units it is calculated by:
where W is the person's weight in pounds and h is the heights in inches.
Write a MATLAB program in a script file that calculates the BMI. For input the program asks the user to enter
his/her weight and height. The program then calculates the BMI rounded to the nearest tenth. For output the
program displays the message: where XX is the value of the BMI. Determine the BMI of
a . tall person that weight
SOLUTION:
clc, clear, close all
W=input(’Please enter your weight in pounds: ');
h=input('Please enter your height in inches: ');
%Define BMI
BMI=round(703*W/h.’2*10)/10;
fprintf('The BMI is %4.1f\n',BMI)
The BMI is 24.6
PROBLEM 2:
The altitude, ñ, as a function of air pressure can be calculated by:
where h is in units of feet and the pressure p in units of millibars (mb). Write a MATLAB program in a script
file that calculates the h for a given p. For input the program asks the user to enter the pressure in units of
millibars. The program then calculates the altitude rounded to the nearest integer. For output the program
displays the message: where XX is the calculated value of h. Determine the
altitude if the pressure is
SOLUTION:
clc, clear, close all
p=input('Please enter the pressure in units of millibars: ');
h=round(145366.45*(1-(p/1013.25)’0.190289));
fprintf('The altitude is %4.0f ft.\n', h)
The altitude is 23915 ft.
PROBLEM 3:
Write a MATLAB program that determines the of the largest sphere that can be inscribed inside a
cone with base radius and height h. For input the program asks the user to enter values for . The
program then calculates r rounded to the nearest tenth. For output the program displays the message: “The
radius of the largest sphere that can be inscribed inside a cone with a base radius of XX in. and
height of XX in., is: XX in.” where XX are the corresponding numerical values. Use the program to
determine r for a cone with and
SOLUTION:
clc, clear, close all
R=input(’Please enter the radius of the cone: ');
h=input('Please enter the height of the cone: ');
r=round(h*R/(sqrt(R’2+h’2)+R)+10)/10;
fprintf('The radius of the largest sphere that can be inscribes inside a cone\n')
The radius of the largest sphere that can be inscribes inside a cone
fprintf(’with a base radius of %5.1f in. and heights of %5.1f in. is: %5.1f in.\n', R,h,r)
with a base radius of 8.0 in. and heights of 22.0 in. is: 1.6 in.
PROBLEM 4:
Radioactive decay can be modeled by the equation:
where A is the amount at time i, is the amount at time , and k is a constant. Write a MATLAB program that
calculates the amount of a radio active material. When executed, the program asks the user to enter the half
life of the material (in years), the current amount of the material , and the number of years from now for
which the amount should be calculated. From this information the program first calculates the constant k and
then the amount at t years. For output the program displays the message: “The amount of the material
after XX years is XX kg" where XX are the corresponding numerical values. Use the program to determine
how much will be left from
SOLUTION:
clc, clear, close all
th=input('Please enter the half-life of the material (in years): ');
AO=input('Please enter the current amount of the material (in lb): ');
t=input(’Please enter the number of years from now for which amount should be calculated: ');
%Define k and A
k=log(2)/th;
A=AO*exp(-k*t);
fprintf('The amount of the material after %7.1f years is %6.3f lb\n', t,A)
The amount of the material after 500.0 years is 49.286 lb
PROBLEM 5:
A fuel tank is made of a half cylinder as shown. Derive an expression for the amount of fuel in gallons
as a function of h. Create a vector for ñ ranging from . with increments of Then calculate the
corresponding volume rounded to the nearest tenth of a gallon. Display the results in a two-column table
where in the first column are the values of h and in the second column the associated values of volume
SOLUTION:
clc, clear, close all
%G1ven
R=14;
h=0: 2 : 14;
V=(R’2*acos((R-h)./R)-(R-h).*sqrt(2*R*h-h.’2))*36/231;
V=round(V*10)/10;
T= [h ' , V' ] ;
fprintf(’ h(in.) V(gallons) \n')
h(in.) V(gallons)
disp(T)
0 0
2.0000 3.0000
4.0000 8.4000
6.0000 15.1000
8.0000 22.6000
10.0000 30.8000
12.0000 39.3000
14.0000 48.0000