Beruflich Dokumente
Kultur Dokumente
In this Lab:
For example,
Volume = π * r2 * h
Where
r is the radius
And
h is the height
For example,
The volume of a cylinder in the above will be expressed in its functional symbol
form as follows
V= f(r, h)
Which is read as Volume V of a cylinder is a function of two variables that is radius
r and height h.
3
Generally, an expression
Just like function of one variable, function of several variables has a domain and
range.
And
The Domain of a function is the set of values to which a function is applied.
The Range of a function is the set of values to which the results belong.
Let’s illustrate the domain and range of a function which describes the volume of a
circular cylinder V(r, h) = π * r2 * h by making a table.
4
And so on…..
Let us now verify the correctness of above table by writing an interactive program
in Matlab.
So, open the Matlab editor and write the following program.
clc;
clear all;
syms V(r,h);
l = length(r1);
for i = 1 : l
end
Enter the volume which is function of two variables radius r and height h
V = pi * r ^ 2 * h
Enter the radius r values as a vector
r1 = [1 2 6]
Enter the height h values as a vector
h1 = [5 10 15]
The values of Volume V at radius r = 1.00 cm and height h = 5.00 cm is 15.71
cm^3
The values of Volume V at radius r = 2.00 cm and height h = 10.00 cm is 125.66
cm^3
The values of Volume V at radius r = 6.00 cm and height h = 15.00 cm is
1696.46 cm^3
6
The above output verifies the above table. Of course user can enter his/her own
values for radius r and height h.
The monthly payment that amortizes a loan of A dollars in t years when the interest
rate is r per year is given by
𝐴𝑟
P = f (A, r, t) = 𝑟
12[1−(1+ )−12𝑡 ]
12
Now, we shall write a program in Matlab which will find for us the monthly payment
when
clc;
clear all;
ripdf = r1 / 100 ;
len = length(t1);
fprintf('Table of Amortized Loan Rate Years and Monthly Payment for Home
Mortgage Payments\n\n');
for i = 1 : len
end
Table of Amortized Loan Rate Years and Monthly Payment for Home Mortgage
Payments
We know that sunlight is a portion of the EM radiation given off by the sun in
particular infrared, visible and ultraviolet light.
Now, our task is to find out power per unit area radiated from the sun’s surface in
the wavelength range 600.0 to 605.0 nm.
The solution to this problem involves the power emitted by a blackbody over a
narrow range of wavelengths, and so involves the spectral emittance I (λ,T) given
by the Planck radiation law
This requires that we find the area under the curve I (λ, T) between 600.00 and
605.00 nm. We will approximate this area as the product of the height at the
median wavelength λ = 602.5 nm and the width of interval, Δλ = 5.00 nm. We know
that sun’s surface is a blackbody with a surface temperature of 5800 K.
We also know that total power radiated per unit area from the sun’s surface at all
wavelengths is 64.2 MW /m2.
We shall solve this problem by writing an interactive program in Matlab, the
program will also tell us what percentage is power radiated per unit area in the
wavelength range 600 to 605 nm, is of the total power radiated per unit area at all
wavelengths.
clc;
clear all;
% Define the total power radiated per unit area by the sun at all
% wavelengths...
tprfs = 6.42e7;
K = (h * c) / (medoflamda * k * T);
fprintf('\n\n');
lamdaf = 605e-9
Thus, the power radiated from the sun’s surface in the wavelength range 600.0
to 605.0 nm is 3.9 *105 W / m2 or 0.39 MW /m2. And this power is 0.6 percent of
the total power radiated from the sun at all wavelengths which is 64.2 MW / m2.
In 1928 Charles Cobb and Paul Douglas published a study in which they modeled
the growth of the American economy during the period 1899 - 1922. They
considered a simplified view of the economy in which production output is
determined by the amount of labor involved and the amount of capital invested.
While there are many other factors affecting economic performance, their model
proved to be remarkably accurate.
P (L, K) = bLαKβ
13
Where,
α and β are the output elasticities of labor and capital, respectively. These
values are constants determined by available technology.
Now, we shall write an interactive program in Matlab which will display for us the
Cobb-Douglas production function during the years from 1899-1922 for various
values of Labour L, and Capital K in the form of a table.
So, open the Matlab editor and write the following program.
% This Program displays the table for Charles Cobb and Paul Douglas model
% for the growth of American Economy during the period 1899-1922 which is
% given by the function of two variables
% P(L, K) = bL^alphaK^beta.
% Where
clc;
clear all;
len = length(Y);
fprintf('\n\n\n')
for i = 1:len
end
Run the program for various inputs and get the corresponding outputs.
In countries with extreme winter weather, the wind-chill index is often used to
describe the apparent extremity of the cold weather. This index or indicator W is a
subjective temperature that depends on actual temperature T and the wind speed
v. Thus, W is a function of T and v, and we can write
W = f (T, v)
The wind-chill index or indicator has been modeled by the following function in USA
customary units.
Where,
Now, our task is to write a program in Matlab which will draw a chart or table for
wind-chill index or indicator for the entered values of actual temperature Ta and
18
wind speed v. The program will use the above function for obtaining the table or
chart.
So, open the Matlab editor and write the following program.
% This program produces the Wind-chill-Index for entered values of wind
% speed and actual temperatures.
clc;
clear all;
n = length(v);
m = length(Ta);
W = round(WCI);
WTable = array2table(W);
WTable
WTable =
12×18 table
28 21 14 7 0 -7 -14 -21 -27 -34 -41 -48 -55 -62 -69 -76
-82 -89
27 20 13 6 -1 -8 -15 -22 -29 -36 -43 -50 -57 -64 -71 -78
-84 -91
26 19 12 5 -2 -9 -16 -23 -30 -37 -44 -51 -58 -65 -72 -79
-86 -93
26 19 12 4 -3 -10 -17 -24 -31 -38 -45 -52 -60 -67 -74 -81
-88 -95
25 18 11 4 -3 -11 -18 -25 -32 -39 -46 -54 -61 -68 -75 -82
-89 -97
25 17 10 3 -4 -11 -19 -26 -33 -40 -48 -55 -62 -69 -76 -84
-91 -98
a) The first step is to set up the vectors that represent the array of domain of x
and y values. For example, we want to plot over the domain -7 <= x <= 7 and
-7 <= y <= 7. We set up these vectors in Matlab as follows.
b) Next, we have to make a grid of points over which we want the heights of
the surface. To achieve this we use the meshgrid(x,y) function that
transforms the domain specified by a single vector or two vectors x and y
into matrices X and Y.
c) Use the matrices X and Y for the evaluation of function of two variables.
d) Use the well-known Matlab built-in functions mesh(), surf(), waterfall() and
others for plotting functions of two variables.
21
The Contour plot of functions of two variables are displayed in Matlab using Matlab
built-in function contour and contourf. The same steps are used for displaying
contour plots.
Let us now write an interactive program in Matlab, which will ask the user to enter
the function of two variables which has to be plotted and the domain of function.
The program will offer the choice to the user to plot various types of surfaces (like
mesh, surf and waterfall, etc.), contour plots and an animated plot of entered
function. The program will also give the choice to user to enter the colourmap.
clc;
clear all;
close all;
[X , Y] = meshgrid(x, y);
switch ch
case 1
mesh(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Mesh Plot');
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
case 2
meshc(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Mesh Contour Plot');
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
case 3
meshz(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Meshz Plot');
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
case 4
surf(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Surf plot');
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
case 5
surfc(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Surf Contour Plot');
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
case 6
waterfall(X,Y,Z);
rotate3d;
colormap(cm)
title('\bf Waterfall Plot')
xlabel('\bf x');
ylabel('\bf y');
zlabel('\bf z');
23
case 7
contour(X,Y,Z,'ShowText','on');
colormap(cm)
title('\bf Contour Map');
xlabel('\bf x');
ylabel('\bf y');
case 8
contourf(X,Y,Z,'ShowText','on')
colormap(cm)
title('\bf Filled Contour Map');
xlabel('\bf x');
ylabel('\bf y');
case 9
mesh(X,Y,Z, 'Linewidth', 1.5)
colormap(cm);
title('\bf Animated Plot')
xlabel('\bf x');
ylabel('\bf y');
end
Some of the graphs created by the above program are given below.
24
25
26
P (L, K) = 1.01L0.75K0.25
And its contour plot, when the values of labour L and capital K lie between 0 and
300.
27
clc;
clear all;
close all;
K = linspace(0,300, 300);
figure(1)
mesh(L1,K1,P)
colormap(colorcube)
figure(2)
colormap(colorcube)
We know that
Let us now make a 3-D plot of this function for the wavelength range
And Temperature
clc;
clear all;
close all;
l = linspace(1e-7, 1e-5,500);
T = linspace(100,2000,500);
K = (h * c) ./ (lamda .* k .* Temp);
31
colormap(colorcube)