Tuesday, March 21, 2017

                                       APPLICATION IN CALCULUS

An equation with one variable can be written in the form f(x) = 0. The solution is the value of x where the function crosses the x-axis (the value of function is zero), which means that the function changes sign at x. Using MATLAB, we can easily find the solution of function.
Syntax for finding solution:

‘function’ is the function to be solved. It can be entered in three different ways:
  • ·         The simplest way is to enter the mathematical expression as string.
  • ·         The function can also be created as a user-defined function in a function file, then name of the function typed as a string.

X0 can be a scalar or a two-element vector. If it is entered as a scalar. It has to be a point near which the function crosses the x-axis. If x0 is entered as a vector of two elements, function should have different sign at these two elements.
Q) Using MATLAB, determine the solution of equation?
                                  x*exp(-x) – 0.2 = 0

fplot('x*exp(-x) - 0.2',[0 8])

By executing above command in MATLAB, we can see the graph of function and from graph we conclude that function has one solution near 0.7 and another solution near 2.8.
>> x1 = fzero('x*exp(-x) - 0.2',0.7)
x1 =

    0.2592
>> x2 = fzero('x*exp(-x) - 0.2',2.8)
x2 =

    2.5426
Therefore, by executing above two commands in MATLAB, we have concluded that function has one solution at 0.2592 and another at 2.5426.
  • ·         The fzero command finds zeroes of a function only where the function crosses the x-axis. It does not find zero at points where the function touches but does not cross the x-axis.
  • ·         [x fval] = fzero('function',x0) assigns the value of the function at x to the variable fval.

Q) Determine the first three positive roots of equation:    2*sin(x) - x.^0.5 + 2.5 = 0 by using MATLAB?

clc
close all
clear all
%By executing following graphs in matlab and by watching following graphs
%we will get approximate ideas about roots
%fplot('2*sin(x)-x.^0.5+2.5',[3 4]);
%fplot('2*sin(x)-x.^0.5+2.5',[6 7]);
%fplot('2*sin(x)-x.^0.5+2.5',[9 10]);
%from first above graph we conclude that one root is near 3.5
%from second above graph we conclude that one root is near 6.3
%from third graph we conclude that one root is near 9.15
x1 = fzero('2*sin(x)-x.^0.5+2.5',3.5);
x2 = fzero('2*sin(x)-x.^0.5+2.5',6.3);
x3 = fzero('2*sin(x)-x.^0.5+2.5',9.15);
fprintf('function has solution at points %f,%f and %f',x1,x2,x3);


*link for downloading program threepositiveroot.m from folder calculus
FINDING A MINIMUM OR A MAXIMUM OF A FUNCTION
In MATLAB, the value of x where a one-variable function f(x) within the interval x1<x<x2 has a minimum can be determined with the fminbnd command which has the form:




     









      
  •       The function can be entered as a string, as the name of a function file, or as the name of an inline function, in the same way as with the fzero command.
  • ·         The value of the function at the minimum can be added to the output by using the option:


[x fval] = fminbnd('function',x1,x2)
Where the value of the function at X is assigned to the variable fval
Consider the function f(x) = x^3 -12*x^2 + 40.25*x -36.5

fplot('x^3 - 12*x^2 + 40.25*x - 36.5',[0 8])

By executing above command in command window, we can see the graph of above function.

>> [x fval] = fminbnd('x^3 - 12*x^2 + 40.25*x - 36.5',0,8)

x =
  5.6073
fval =

  -11.8043

Therefore minimum of above function at x = 5.6073 and value of function at this point is -11.8043.
We should note that fminbnd command gives local minima and not the absolute minimum which is at x=0.
  • ·         fminbnd command tries to find local minima and not the absolute minima. If a local minimum is not found, the function returns the end point (x1 or x2) with the lower function value.
  • ·         The fminbnd command can also be used to find the maximum of a function. This is done by multiplying the function by -1 and finding the minimum.

NUMERICAL INTEGRATION
 Integration is a common mathematical operation in Science and Engineering. It is assumed that reader has basic knowledge of integration.
There are two MATLAB built-in functions, quad and trapz that are used for finding integration. Syntax for using quad command:


The function can be entered as string, as the name of a function file in the same way as with the fzero command.
Q) Use MATLAB to calculate the integration of function f(x) = 1/(0.8x2 + 0.5x+2) from x = 0 to x = 8?
                                                                            OR
Q) Use MATLAB to calculate the area bounded by curve y = 1/(0.8x2 + 0.5x+2), x=0, x=8 and x-axis?

clc
clear all
a = quad('(0.8*x.^2+0.5*x+2).^-1',0,1);

*link for downloading program iintegration.m from folder intdiffeq
Therefore by using quad command we can find integration in just one step.

Trapz command:
The trapz command can be used for integrating a function that is given as data points. It uses numerical trapezoidal method of integration. Syntax for using command:
trapz(x,y)
where x and y are vectors with the x and y coordinates of the points respectively. The vectors must be of same length. For example:

>> X = [0 1 2 3 4 5];
>> Y = [0 1 2 3 4 5];
>> trapz(X,Y)

ans =

   12.5

Therefore area bounded by curve X-Y is equal to 12.5. We can easily verify this from the X-Y plot shown below.


























No comments:

Post a Comment