Sie sind auf Seite 1von 32

1

LAB2: FUNCTIONS OF SEVERAL VARIABLES


PART A

In this Lab:

 We shall introduce the concept of functions of several variables.


 We shall demonstrate some practical examples of functions of several
variables by writing programs in Matlab.
 We shall demonstrate how to plot functions of two variables in Matlab.
 We shall demonstrate how to plot contour plots in Matlab.
 We shall give some practical examples of functions of two variables by
plotting them in Matlab.

1.1 INTRODUCTION to the Concept

We know from Calculus courses that in Single-Variable Calculus when we define a


function, then dependent quantity depends on only one independent quantity.
However, in Multi-Variable Calculus when we define a function then dependent
quantity depends on two or more independent quantities. Thus, this leads us to the
concept of functions of several variables.

For example,

When we calculate the volume of a cylinder using the formula


2

Volume = π * r2 * h

Where
r is the radius
And
h is the height

We can see that dependent quantity volume V of a cylinder is depending on two


independent quantities and these are radius r and height h of a cylinder.

Therefore, we can say that

V is a function of two variables r and h.

1.1.1 Symbolization for Functions of Several Variables

The symbolization and expression for functions of several variables is similar or


analogous to functions of one variable.

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

s = f(x1, x2 …………… xn)

Means that s is a function of n variables x1 …………. xn

And a unique value of dependent variable s is determined by specifying the values


of independent variables x1 ………… xn

1.1.2. DOMAIN AND RANGE OF FUNCTIONS OF SEVERAL VARIABLES

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

DOMAIN: Set of values to which RANGE: Set of values to which results


function is applied. belong
Various values in the domain of V Various values in the range of V

When r = 1cm and h = 5cm V(1,5) = π * 12 * 5 = 15.70 cm3


When r = 2cm and h = 10 cm V(2,10) = π * 22 *10 = 125.66 cm3
When r = 6 cm and h = 15 cm V(6, 15) = π * 62 * 15 = 1696 cm3

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;

% Create Symbolic Function V and symbolic variables r and h

syms V(r,h);

% Enter the Volume V which is function of two variables r and h

V = input('Enter the volume which is function of two variables radius r and


height h\n V = ');

% Vectors r1 and h1 should be of same length.

% Enter the various values of radius r in cm as a vector.

r1 = input('Enter the radius r values as a vector \n r1 = ');

% Enter the various values of height h in cm as a vector.

h1 = input('Enter the height h values as a vector \n h1 = ');

% Find the length of vector r1 which is equal to length of vector h1


5

l = length(r1);

% Find the values of volume V at various values of radius r and height h

Vvalues = double(subs(V, {r,h}, {r1, h1}));

% Display the Values of Volume.

for i = 1 : l

fprintf('The values of Volume V at radius r = %.2f cm and height h =


%.2f cm is %10.2f cm^3\n', r1(i), h1(i), Vvalues(i));

end

Run the program as follows and get the desired output.

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.

1.2 Some Practical Examples of Functions of Several Variables

Next, we shall give some practical applications of Functions of Several Variables.

1. HOME MORTGAGE PAYMENTS

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

 Home mortgage of $ 100,000 that will be amortized over 30 years with an


interest rate of 8 % per year.
 Home mortgage of $ 100,000 that will be amortized over 30 years with an
interest rate of 10 % per year.
 Home mortgage of $ 100,000 that will be amortized over 20 years with an
interest rate of 8 % per year.
7

The program will display the output in the form of a table.

% This program finds the Home Mortgage Payments

clc;
clear all;

% Create Symbolic Function P and symbolic variables A , r and t.

syms P(A , r , t);

% Enter the payment.

P = input('Enter the monthly payment which is function of A , r and t\n P =


');

% Enter the Loan to be Amortized.

A1 = input('Enter the Amortized Amount as a vector\n A1 = ');

% Enter the rate in percentage.

r1 = input('Enter the rate in percentage as a vector \n r1 = ');

% Enter the Years.

t1 = input('Enter the years as a vector \n t1 = ');

% Note: A1 ,r1 amd t1 should be of same length.

% Convert the rate in percent decimal form.

ripdf = r1 / 100 ;

% Find the length of vector t1 which is equal to length of A1 and r1

len = length(t1);

% Find the Payment Values.

Pvalues = double(subs(P, {A , r , t}, {A1 , ripdf ,t1}));

% Create the output array.


8

outputarr = [A1' r1' t1' Pvalues'];

% Display the table title.

fprintf('Table of Amortized Loan Rate Years and Monthly Payment for Home
Mortgage Payments\n\n');

% Display Column Headings

fprintf(' Amortized Amount Rate Years


Monyhly Payment\n');
fprintf(' **************** *****
******* ********************\n');

% Display the output.

for i = 1 : len

fprintf('%20.2f $ %23.2f %19.2f %25.2f $\n', outputarr(i,:));

end

Run the program as follows and get the desired output.

Enter the monthly payment which is function of A , r and t


P = (A * r) / (12 * (1 - (power(1 + r / 12, -12*t ))))
Enter the Amortized Amount as a vector
A1 = [100000 100000 100000]
Enter the rate in percentage as a vector
r1 = [8 10 8]
Enter the years as a vector
t1 = [30 30 20]
9

Table of Amortized Loan Rate Years and Monthly Payment for Home Mortgage
Payments

Amortized Amount Rate Years Monyhly Payment


**************** ***** *******
********************
100000.00 $ 8.00 30.00 733.76 $
100000.00 $ 10.00 30.00 877.57 $
100000.00 $ 8.00 20.00 836.44 $

And this gives us the desired output.

2. A SLICE FROM SUNLIGHT

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

I (λ, T) = 2πhc2/λ5 (ehc/λkT - 1) (Planck’s Radiation Law)


10

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.

So open the Matlab editor and write the following program.

clc;
clear all;

% Define the Constants...

h = 6.626e-34; % Planck's Constant

c = 2.998e8; % Speed of light

k = 1.38066e-23; % Boltzmann's Constant.

% Define the total power radiated per unit area by the sun at all
% wavelengths...

tprfs = 6.42e7;

% Enter the temperature of sun.

T = input('Enter the temperature of Sun \n T = ');

% Enter the Initial Value of wavelength range.

lamdai = input('Enter the initial value of Wavlength Range \n lamdai = ');

% Enter the Final Value of wavelength range.

lamdaf = input('Enter the final value of Wavlength Range \n lamdaf = ');

% Find the median wavelength..


11

medoflamda = median([lamdai lamdaf]);

% Find the width of interval.

dlamda = lamdaf - lamdai;

% Compute the term of Planck radiation law.

K = (h * c) / (medoflamda * k * T);

% Find the spectral emittance...

Ilamda = (2 * pi *h * c^2) / ((medoflamda^5) * (exp(K) - 1));

% The intensity in the entered wavelength range..

Ilamda_in_wavlen_range = Ilamda * dlamda;

% Find the percent of total power radiated.

percentoftotalpower = (Ilamda_in_wavlen_range / tprfs) * 100;

% Print the output...

fprintf('\n\n');

fprintf('The intensity in the entered wavelength range %.2e nm is %.2e W /


m^2\n\n', dlamda , Ilamda_in_wavlen_range );

fprintf('And this power radiated is %.2f percent of total power


radiated\n\n', percentoftotalpower)

Run the program as follows and get the desired output.

Enter the temperature of Sun


T = 5800
Enter the initial value of Wavlength Range
lamdai = 600e-9
Enter the final value of Wavlength Range
12

lamdaf = 605e-9

The intensity in the entered wavelength range 5.00e-09 nm is 3.90e+05 W / m^2

And this power radiated is 0.61 percent of total power radiated

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.

3. Cobb Douglas Production Function

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.

The function they used to model production was of the form:

P (L, K) = bLαKβ
13

Where,

 P = total production (the monetary value of all goods produced in a year)

 L = labor input (the total number of person-hours worked in a year)

 K = capital input (the monetary worth of all machinery, equipment, and


buildings)

 b = total factor productivity

 α 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

% • P = total production (the monetary value of all goods produced in a year)


%
% • L = labor input (the total number of person-hours worked in a year)
%
14

% • K = capital input (the monetary worth of all machinery, equipment, and


buildings)
%
% • b = total factor productivity
%
% • alpha and beta are the output elasticities of labor and capital,
respectively.
% % These values are constants determined by available technology.

clc;
clear all;

% Enter the Years as vector

Y = input('Please Enter the Years as Vector\n Y = ');

% Enter the Labour as vector

L = input('Enter the Labour as Vector\n L = ');

% Enter the Capital as vector

K = input('Enter the Capital as Vector\n K = ');

% Enter the total factor productivity

b = input('Enter the total factor productivity\n b = ');

% Enter the output elasticity for labour.

alpha = input('Enter the output elasticity for labour\n alpha = ');

% Enter the output elasticity for capital.

beta = input('Enter the output elasticity for capital\n beta = ');

% Enter the production as function of Labour L and Capital K

P = input('Enter the production as function of L and K\n P = ');

% Find the length of years.


% Vectors Years Y, Labour L and capital K should be of same length.

len = length(Y);

% Create the output Array.

outputarr = [Y' , L' , K' , P'];

% Print the output Table.


15

fprintf('\n\n\n')

fprintf('The Table Describing The Cobb-Douglas Production Function\n')


fprintf('\n\n');
fprintf(' Years Y Labour L Capital K
Production P\n');
fprintf(' ******** ******** **********
************\n');

for i = 1:len

fprintf('%17.2f %21.2f %17.2f %13.2f \n', outputarr(i,:))

end

Run the program as follows and get the desired output.

Please Enter the Years as Vector


Y = [1899:1:1922];
Enter the Labour as Vector
L = [100 105 110 117 122 121 125 134 140 123 143 147 148 155 156 152 156 183
198 201 196 194 146 161];
Enter the Capital as Vector
K = [100 107 114 122 131 138 149 163 176 185 198 208 216 226 236 244 266 298
335 366 387 407 417 431];
Enter the total factor productivity
b = 1.01
Enter the output elasticity for labour
alpha = 0.75
Enter the output elasticity for capital
beta = 0.25
Enter the production as function of L and K
P = b.*(L.^alpha).*(K.^beta)

This input leads to the following output.


16

The Table Describing The Cobb-Douglas Production Function

Years Y Labour L Capital K Production P


******** ******** ********** ************
1899.00 100.00 100.00 101.00
1900.00 105.00 107.00 106.55
1901.00 110.00 114.00 112.10
1902.00 117.00 122.00 119.41
1903.00 122.00 131.00 125.43
1904.00 121.00 138.00 126.29
1905.00 125.00 149.00 131.92
1906.00 134.00 163.00 142.13
1907.00 140.00 176.00 149.73
1908.00 123.00 185.00 137.58
1909.00 143.00 198.00 156.67
1910.00 147.00 208.00 161.93
1911.00 148.00 216.00 164.30
1912.00 155.00 226.00 172.03
1913.00 156.00 236.00 174.74
1914.00 152.00 244.00 172.80
1915.00 156.00 266.00 180.05
1916.00 183.00 298.00 208.79
1917.00 198.00 335.00 228.08
1918.00 201.00 366.00 235.82
1919.00 196.00 387.00 234.66
1920.00 194.00 407.00 235.81
1921.00 146.00 417.00 191.70
1922.00 161.00 431.00 208.00
17

Run the program for various inputs and get the corresponding outputs.

4. Wind Chill Index

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.

W (T, v) = Twc = 35.74 + 0.6215Ta – 35.75(v0.16) + 0.4275T (v0.16)

Where,

T is the actual temperature and is entered in Fahrenheit.

v is the wind speed and is entered in miles per hour (mph).

Always bear in mind that

Wind-chill temperature is defined only for temperatures at or below 10 °C (50 °F)


and wind speeds above 4.8 kilometers per hour (3.0 mph).

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;

% Enter the Wind speeds in mph as vector.

v = input('Enter the wind speeds in miles per hour as a vector\n v = ');

% Enter the actual temperatures as vector.

Ta = input('Enter the actual temperatures in Fahrenheit as a vector\n Ta =


');

% Find the length of vector v.

n = length(v);

% Find the length of vector Ta.

m = length(Ta);

% Find the Wind-Chill Index


for i = 1:n
for j = 1:m

WCI(i ,j) = 35.74 + 0.6215.*Ta(j)- 35.75.*(v(i).^0.16) +


(0.4275.*Ta(j)).*((v(i).^0.16));
end
end

% Round the values.

W = round(WCI);

% Convert the array W to table using Matlab built-in function array2table


19

WTable = array2table(W);

% Display the output.

fprintf('\n The Desired Wind-Chill Index Chart is\n ');

WTable

Run the program as follows and get the desired output.

Enter the wind speeds in miles per hour as a vector


v = [5 10 15 20 25 30 35 40 45 50 55 60]
Enter the actual temperatures in Fahrenheit as a vector
Ta = [40 35 30 25 20 15 10 5 0 -5 -10 -15 -20 -25 -30 -35 -40 -45]

The Desired Wind-Chill Index Chart is

WTable =

12×18 table

W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13


W14 W15 W16 W17 W18
__ __ __ __ __ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
___ ___ ___

36 31 25 19 13 7 1 -5 -11 -16 -22 -28 -34 -40 -46 -52


-57 -63
34 27 21 15 9 3 -4 -10 -16 -22 -28 -35 -41 -47 -53 -59
-66 -72
32 25 19 13 6 0 -7 -13 -19 -26 -32 -39 -45 -51 -58 -64
-71 -77
30 24 17 11 4 -2 -9 -15 -22 -29 -35 -42 -48 -55 -61 -68
-74 -81
29 23 16 9 3 -4 -11 -17 -24 -31 -37 -44 -51 -58 -64 -71
-78 -84
28 22 15 8 1 -5 -12 -19 -26 -33 -39 -46 -53 -60 -67 -73
-80 -87
20

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

And this gives us the desired output.

1.3 DISPLAYING GRAPHS OF FUNCTIONS OF TWO VARIABLES

To display the graph of function of two variables, z = f(x, y) in Matlab we perform


the following steps.

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.

x = -7: .5: 7; and y = -7:.5:7;

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

1.3.1 Displaying Contour Plots of Functions of Two Variables

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.

So open the Matlab editor and write the following program.

clc;
clear all;
close all;

x = input('Enter the x vector\n x = ');

y = input('Enter the y vector\n y = ');

[X , Y] = meshgrid(x, y);

Z = input('Enter the function\n Z = ');

cm = input('Enter the colormap as a string\n cm = ' , 's');

fprintf('Enter the following choices\n ');

fprintf('\t 1:- For drawing a mesh surface plot\n');


fprintf('\t 2:- For drawing a mesh contour surface plot\n');
fprintf('\t 3:- For drawing a meshz surface plot\n');
fprintf('\t 4:- For drawing a surf surface plot\n');
fprintf('\t 5:- For drawing a surf contour plot\n');
fprintf('\t 6:- For drawing a waterfall plot\n');
fprintf('\t 7:- For drawing a contour plot\n');
fprintf('\t 8:- For drawing a contour filled plot\n');
22

fprintf('\t 9:- For An Animated Plot\n');

ch = input('\n\n Enter your choice\n ch = ');

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');

% Modify the z-axis and draw again

for zrotate = -40:0.2:100


view(zrotate,40)
drawnow
end

end

Run the program and enter your functions of two variables.

Some of the graphs created by the above program are given below.
24
25
26

1.3.2 Some Practical Examples of Plots of Functions of Two Variables

Next, we shall consider some practical examples of plots of functions of two


variables.

1. COBB-DOUGLAS PRODUCTION FUNCTION

Let us now draw the graph of the Cobb-Douglas production function

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

So open the Matlab editor and write the following program.

clc;
clear all;
close all;

% Set the values of Labour

L = linspace(0, 300, 300);

% Set the values of Capital

K = linspace(0,300, 300);

% Create the 2-D grid.

[L1 , K1] = meshgrid(L,K);

% Evaluate the Production function.

P = 1.01 .* (L1.^0.75) .* (K1.^0.25);

% Dispay the graph of Cobb-Douglas Production function.

figure(1)

mesh(L1,K1,P)

% Add the title and labels to the graph.

title('\bf Cobb-Douglas Production Function');


xlabel('\bf LABOUR');
ylabel('\bf CAPITAL');
zlabel('\bf Production');

% Set the colormap to colorcube.

colormap(colorcube)

% Display the contour-plot of Cobb-Douglas production function.

figure(2)

contourf(P, 'g', 'Showtext', 'on');

% Add the title and labels


28

title('\bf Cobb-Douglas Production Function');


xlabel('\bf LABOUR');
ylabel('\bf CAPITAL');

% Set the colormap to colorcube.

colormap(colorcube)

When we run this program we get the following graphs.


29

2. Planck’s Radiation Law

We know that

In 1900, Max Planck succeeded in deriving an exponential model by using natural


exponential function which shows that how the intensity of black body radiation
varies with temperature and wavelength. This model matched remarkably well
with experimental intensity distribution curves.
The following is the result

I (λ, T) = 2πhc2/λ5 (ehc/λkT - 1) (Planck’s Radiation Law)


30

As we can see I (λ, T) is a function of two variables that is wavelength and


temperature.

Let us now make a 3-D plot of this function for the wavelength range

0.1 <= λ <= 10µm

And Temperature

100 <= T <= 2000K

So open the Matlab editor and write the following program.

clc;
clear all;
close all;

% Define the Constants...

h = 6.626e-34; % Planck's Constant

c = 2.998e8; % Speed of light

k = 1.38066e-23; % Boltzmann's Constant.

% Set the Values for Lamda.

l = linspace(1e-7, 1e-5,500);

% Set the Values for Temperature.

T = linspace(100,2000,500);

% Create the 2-D grid.

[lamda , Temp] = meshgrid(l,T);

% Compute the term of Planck radiation law.

K = (h * c) ./ (lamda .* k .* Temp);
31

% Evalute the function.

I = (2 * pi * h * c^2) ./ ((lamda.^5) .* (exp(K) - 1));

% Plot the function

mesh(lamda,Temp, I, 'Linewidth', 2.5);

% Use the logarithmic scale for Lamda.

set(gca, 'xscale' , 'log')

% Add the title and Labels

title('\bf Plancks Radiation Law', 'color', [0 0.392 0], 'fontsize', 15)


xlabel('\bf Wavelength \lambda(\mum)', 'color', [0 0.392 0], 'fontsize', 15)
ylabel('\bfTemperature(Kelvin)', 'color', [0 0.392 0], 'fontsize', 15);
zlabel('\bf Intensity I(\lambda,T)', 'color', [0 0.392 0], 'fontsize', 15')

% Set the colormap to colorcube

colormap(colorcube)

Run the program and get the following plot.


32

Das könnte Ihnen auch gefallen