0% found this document useful (0 votes)
1 views

Matlab-03

MATLAB is a high-performance numerical computation and visualization software that features an interactive environment with built-in functions for various scientific computations, graphics, and animations. The document outlines basic commands, arithmetic operations, and array manipulations in MATLAB, as well as how to create plots and visualize data. It also includes examples of calculations, array operations, and geometric series, demonstrating the software's capabilities for both beginners and advanced users.

Uploaded by

Md Rony
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Matlab-03

MATLAB is a high-performance numerical computation and visualization software that features an interactive environment with built-in functions for various scientific computations, graphics, and animations. The document outlines basic commands, arithmetic operations, and array manipulations in MATLAB, as well as how to create plots and visualize data. It also includes examples of calculations, array operations, and geometric series, demonstrating the software's capabilities for both beginners and advanced users.

Uploaded by

Md Rony
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

MATLAB:

MATLAB is a software package for high performance numerical computation and


visualization .it provides an interactive environment with hundreds of build in
function for technical computation,graphics and animation.
Best of all it also provides easy extensibilitywith its own high level programming
language. The name MATLAB stands for MATrixLABoratory.

MATLABs build in function provides excellent tolls for linear algebra


(computations,data analysis,optimization,numerical solution of ordinary
differential equations (ode”s),quadratic and many other type of scientific
computation.
There are numerous for 2-D and 3-D graphics as well as for animation. Also for
those whocan not do with their fortran or c codes.

Normal MATLAB Normal MATLAB Normal MATLAB


command command command
π pi sine sin Sinh2x (sinh(x))^2
√x Sqrt(x) cosine cos a+ib a+ib
ex Exp(x) tangent tan √a+ib
Sqrt( a+ib)
3
lnx Log(x) secant sec √x (x)^(1/3)
xn x^n Sin-1 asin Tan-1 atan
× * Cos-1 acos Cot-1 acot
÷ / Sin2x (sin(x))^2 cosecant cosec

Goal:
(1)To learn how to open MATLAB.
(2)Do a few trivalcalculation.(3)Quit MATLAB.
MATLAB commands:
(1) Plot==creat a 2-D line plot.
(2) Axes==changes the aspect the ratio of x and y axes.
(3) X label==annotates the x axis.
(4) Y label==annotates the y axis.
(5) Title==puts a title on the plot.
(6) Print==prints a hardcopy of the plot.
WHAT WE ARE GOING TO LEARN:
*How to do simple arithmetic calculation.
* How to assign values to variables.
*How to suppers screen output.
*How to quit matlab.
Creating and working arrays and numbers:

***some example :
(1) compute y=22+lnπ sinx
Ans:
>> x=30;
>> y=2^2+log(pi)*sin(x)
y = 2.8690

(2)compute 25/25-1 and compare with (1-1/25)-1.

Ans:>> 2^5/(2^5-1)

ans = 1.0323

>> (1-1/(2^5+1))^-1

ans = 1.0313

those results are same.

(3) compute 3(√5-1)/(√5+1)2-1.

Ans:>> 3*(sqrt(5)-1)/(sqrt(5)+1)^2-1

ans =-0.6459

(4)Find the area A=πr2 with r=π1/3-1.

Ans:>> r=(pi)^(1/3)-1;

>> A=pi*r^2
A = 0.6781

write the command to the following terms.


(1)e3→>>exp(3) (2)ln(e3)→>>log(exp(3)) (3)log10(e3)→>>log10(exp(3))
(4)sin π/6→>>sin(pi/6) (5)tan π/2→>>tan(pi/2)

(6)sin2π/6+cos2π/6

Ans:>> (sin(pi/6))^2+(cos(pi/6))^2

ans = 1

(7)If y=cosh2x-sinh2x with x=32π ,compute the result.

Ans:>> x=32*pi;

>> y=(cosh(x))^2-(sinh(x))^2

y= 0

(8)Find the value of 1+3i/1-3i.

Ans:>> (1+3i)/(1-3i)

ans = -0.8000 + 0.6000i

(9)Find the value of eiπ/4 .

Ans:>>cos(pi/4)+i*sin(pi/4)

ans = 0.7071 + 0.7071i

ARRAY:
An array is a list of numbers or expression arranged in horizontal row and vertical
columns.
*When an array has only one row or column then it is called vector.
*An array with M row and N columns is called a matrix of size (M*N).
What we are going to learn:
(1)how to creat row and column vectors.
(2)how to creat avector of n numbers linearly spaced between two given numbers
a and b.
(3)how to do simple arithmetic operation on vector.

HOW TO DO ARRAY OPERATION:


# .* term by term multiplication.
# ./ term by term division.
# .^ term by term exponential.
(5) how to use trigonometric functions with array argument.
(6) how to use elementary math function such as square root, exponential,
logarithmwith array argument.
Goal:
(1)To learn how to create array and vectors,and how to perform arithmetic and
trigonometric operation on them.

## Create a row vector with three element.


solution:-
>> x=[1 2 3]
>>x =[1 2 3]
#Create a column vector with three element.
Solution:-
>>x=[1;2;3]

>>x=[ ]

***Creat a vector x with 5 element linearly spaced between 0 to 10.


Solution:-
X=linspace(0,10,5);
##Compute this √xsinx andsinx√x ,and compare it.
Solution:-
>>x=linspace(0,100,50);
>>y=sqrt (x).*sin(x);
>>z=sin(x).*sqrt(x);
Result y=z
QQ.If m=0.5, c=-2, compute y=mx+c at the following x co-ordinates
X=0,1.5,3,4,5,7,8,10

Solution:-
>> m=.5;
>> c=-2;
>> x=[0,1.5,3,4,5,7,9,10];
>> y=m*x+c
y = -2.0000 -1.2500 -0.5000 0 0.5000 1.5000 2.5000 3.0000

QQ. Creat a vector t with elements, t=1,2,3,4,5,6,7,8,9,10, now compute the


problem .
(1)x=t sint(2)y=t-1/t+1 (3) z=sint2/t2
Solution:
(1)>> t=linspace(1,10,10);
>> x=t.*sin(t)
x=
0.8415 1.8186 0.4234 -3.0272 -4.7946 -1.6765 4.5989 7.9149 3.7091
-5.4402
(2)>> y=(t-1)./(t+1)

y = 0 0.3333 0.5000 0.6000 0.6667 0.7143 0.7500 0.7778 0.8000


0.8182
(3)>> z=sin(t.^2)./(t.^2)
z = 0.8415 -0.1892 0.0458 -0.0180 -0.0053 -0.0275 -0.0195 0.0144 -
0.0078 -0.0051

**If t and x any array such that t=(1,2,3,……….10) and x=(15,16,17,…………,25)


then compute the two variable by addition or substraction.
solution:
>> t=linspace(1,10,10);
>> x=linspace(15,25,10);
>> y=t+x
y = 16.0000 18.1111 20.2222 22.3333 24.4444 26.5556 28.6667 30.7778
32.8889 35.0000

>> z=t-x
z =-14.0000 -14.1111 -14.2222 -14.3333 -14.4444 -14.5556 -14.6667 -14.7778
-14.8889 -15.0000

Points on a circle:
All points with coordinates x=rcosѲ and y=rsinѲwhere r is a
constant lie on a circle with radius r,that is the satisfied equation
x2+y2=r2 .
***Create a column vector Ѳ with the values 0,π/4,π/2,3π/4,π and finally
5π/4,take r=2,and compute the column vectors x and y. check that x and y indeed
satisfy the equation of circle by computing the radius r=√(x2+y2).
Solution:
>>theta=[0;pi/2;pi/4;(3*pi)/2;pi;(5*pi)/2];
>> r=2;
>> x=r*cos(theta);
>> y=r*sin(theta);
>> r=sqrt(x.^2+y.^2)
>>plot(x,y)
r= 2
2
2
2
2
2
Figure:
2

1.5

0.5

-0.5

-1

-1.5

-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2

***Geometric series:
The sum of geometric serics 1+r+r2+r3+………..+rn
1)Approches the limit 1/1-r for r<1
2)Take r=0.5 and create another vector x=[r0,r1,r2……..rn]
3)Now the sum of the vector with command S=s(sum).
4)Calculate the limit 1/1-r and compare the S(sum).
5)Repeat the produce taking from 0 to 50 and the from 0 to 100.
Ans
2) >> n=linspace(0,10,11)

n=0 1 2 3 4 5 6 7 8 9 10

2) >> r=0.5;
>> x=(r.^n)
x = 1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156
0.0078 0.0039 0.0020 0.0010
3) >> S=sum(x)
S = 1.9990
4) >> p=1/(1-r)
p=2
5) >>n=linspace(0,50,51);
>> r=0.5;
>> x=(r.^n)
x = Columns 1 through 16
1.0000 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156 0.0078
0.0039 0.0020 0.0010 0.0005 0.0002 0.0001 0.0001 0.0000
Columns 17 through 32
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 33 through 48

0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000


0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 49 through 51
0.0000 0.0000 0.0000
***Creating and printing simple plots:
Goal:
1)How to make a simple 2-D plots in MATLAB and print it out. What we
are going to learn.
2)How to generate x and y co-ordinates of n equidistance points a unit
circle .
3)How to create plot X vs Y and thus create the cicle.
4)How to set the scale of the x and y axis to be the same ,so that the
circle looks like a circle and not as ellipse.
5)How label the axis with text strings.
6)How to tittle the graph with a text.
7)How to tittle the strings .
***Ex: You are requested to draw a circle of unit radius by using the
parametric equations of a unit radius.
Ans:
>>theta=linspace(0,2*pi,100);
>> r=1;
>> x=r*cos(theta);
>> y=r*sin(theta);
>>plot(x,y)
>>axis('equal');
>>xlabel('X');
>>ylabel('Y');
>>tittle(‘circle of unit radius’)

0.8

0.6

0.4

0.2

0
Y

-0.2

-0.4

-0.6

-0.8

-1 -0.5 0 0.5 1
X

***A simple sine plot


plot y=sinx, 0 ,taking 100 linearly spaced points in the given
interval label the axes and put plot created by ‘’your name’’ in the title.
Solution:
>> x=linspace(0,2*pi,100);
>> y=sin(x);
>>plot(x,y);
>>xlabel('x axis');
>>ylabel('y axis');
>> title('Graph of sin(x) is created by 3rd batch')

Graph:
Graph of sinx is created by 3rd batch
1

0.8

0.6

0.4

0.2
y axis

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
x axis

Line style:
Make the same plots as above but rather than displayeding the graphs
as a curve , show the unconnected data points, to display the data
points with small circles ,use plots (x,y,’o’).Now combine the two plots
with the command plot (x,y,x,y.’o’).to show the line through the data
points as well as distinct data points.
Example: As exponentially decaying sin plot;

***Plot y=e-0.4xsinx, 0 , talking 10,50 and 100 points in the


interval.
Ans:>> x=linspace(0,4*pi,50);
>> y=exp(-0.4*x).*sin(x);
>>plot(x,y)
>>xlabel('X')
>>ylabel('Y')
>>title('the graph of exponential function')

the graph of exponential function


0.6

0.5

0.4

0.3

0.2
Y

0.1

-0.1

-0.2
0 2 4 6 8 10 12 14
X
Space
curve: Use the command plot 3(x,y,z) to the plots circular helix.
X(t)=sint, y(t)=cost, z(t)=t, o
Ans:
>>linspace(0,20,21);
x=sin(t);
y=cos(t);
z=t;
plot3(x,y,z)
xlabel('X')
ylabel('Y')
t=linspace(0,20,21);
x=sin(t);
y=cos(t);
z=t;plot(x,y,x,z)
>>linspace(0,20,21);20,21);
Graph:
20

15

10

-5
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

****Overlay plot:
plot y=cosx and z=1-x2/2+x4/4 for 0
same plot
Solution:

>>x=linspace(0,pi,100 )
>>y=cos(x);
>>z=1-x.^2/2+x.^4/2;
>>plot(x,y,x,z);
>>plot(x,y,x,z,'*');
>>xlabel('X');
>>ylabel('Y');
>>title('the graph of cosx and z');
>>legend('cos(x),'z');
the graph of cosx and z
45
cos(x)
Graph:
40 z

35

30

25

20
Y

15

10

-5
0 0.5 1 1.5 2 2.5 3 3.5
X

Variable in workspace:
(1) Type “who” see the variables in your workspace.
(2) Type ‘’whos’’ to get more information
(3) Type *theta,x,y+ to see the value of Ѳ,x,y listed as these commands .
(4) To transpose them type a single right quote(‘) after their name.

*** Write a MATLAB command to convert the temperature from


celcius to fahrenhite .
Sol: >> c=8;
>> F=9*c/5+32
F =46.4000
***Write a MATLAB command to find the interest on $1000 at the rate
of 6% a year at the end of 5 years if the interest in compounded.
1) Annually
2) Semi annually
3)Quarterly
4)Monthly
5)Daily
1) Ans:
>> p=1000;
>> i=.06;
>> n=5;
>> m=1;
>> a=p+(1+i/m)^(m*n)
a = 1.0013e+003

2)Ans:
>> p=1000;
>> i=.06;
>> n=5
>> m=2;
>> a=p*(1+i/m)^(m*n)
>>a = 1.3439e+003
3)Ans:
>> p=1000;
>> i=.06;
>> n=5
>> m=4;
>> a=p*(1+i/m)^(n*m)
>>a = 1.3469e+003
4)Ans:
>> p=1000;
>> i=.06;
>> n=5
> m=12;
>> a=p*(1+i/m)^(m*n)
a = 1.3489e+003
5)Ans:
>> p=1000;
>> i=.06;
>> n=5;
>> m=365;
>> a=p*(1+i/m)^(m*n)
a = 1.3498e+003

MATRIX:
A matrix is entered row wise with consecutive elements of a row,
separated by a space or a command and the columns are separated by
semicolons . The entire matrix must be enclosed within square
brackets.
**Write a MATLAB input command for the following matrices.
1)A=[ ]
Ans:>>A=[1 2 5;3 9 0]
2) B=2xlnx+siny
5i 3+2i
Ans:>>B=[2*x log(x)+sin(y);5*i 3+(2*i)]

3)A=[ ]

Ans:>>A=[1 3 9;5 10 15;0 0 -5]


4)A=1/3 5.55sinx 9.35 0.097
2/x+2lnx 3 0 6.555
5x-23/55 x-3 xsinx √3
Ans:x=2;
>> A=[1/3 5.55*sin(x) 9.35 0.097;2/(x+2*log(x)) 3 0 6.555;(5*x-23)/55 x-
3 x*sin(x) sqrt(3)]

A =[ ]

*** Indexing(or subscripting):


A(I,j)=refers to the element aij of the matrix.
A(m:n,k:l)=specifies rows m to n and columns k to l of a matrix A.
A(:,5:20)=refers to the elements in columns 5 through 20 of all rows of
A.
A(2:10,:)=refers to the elements in row 2 through 10 of all columns of
matrix A.
***Dimension:size(A) →gives the dimension of A *m,n+
B=[ ]
B(2,3)=5
B=[ ]
C(3,1;3)=[1 2 3]
Produces C=[ ]

***sample question: use (A (3,1:3) such as command) to change the


row and column.

***Enter the matrix A=[ ]

1) Find A23 , A31.


2) Re-place A33 by 9.
3) Create a submatrix A taking rows from 2 to 3 and columns from 1 to
3.
4)Obtain a submatrix of A by taking rows from 2 to 3 and all columns.
1) >>A(2,3)
ans = 6
>>A(3,1)
ans = 7
2)>>A(3,3)
ans = 9
3)>>A(2:3,1:3)
ans =[ ]
4)>>A(2:3,:)
ans =[ ]
***Appending a row or column : A can be easily appending to an
existing matrix provided the row has the same length of the rows of
existing matrix. The something goes for columns.
The command A=[A U] appends the column vector U to the column A.
While A =[A;V] appending the row vector V to the rows of A.
***A row or column of any size may be appended to null matrix.
If A=1 0 0
0 1 0
0 0 1
U=[5 6 7]
V=2
3
4
1)Appends U to the rows of A.
2)Appends V to the column of A
3)Appends u’ to the column of A.
Ans: >> x=[A;u]
x=

2)ans;>> y=[A v]

>>y =[ ]

3)>> u'

ans = [ ]

>> Z=*A u’+

z =[ ]

4) Ans: A=[A u]
??? Error using ==>horzcat
CAT arguments dimensions are not consistent.
It is not possible in MATLAB, because the dimensions of the matrix are
not acceptable for this operation.
5)Ans: >>T=[];
>>S=[1 6 9];
>>M=[T;S]
M=[1 6 9 ]
##Deleting a row or column :
Any row or columns of a matrics can be deleted by setting the row or
column to a null vector.
A(2,:)=*+→Delets the 2nd row a matrix A.
A(:,3)=*+→Delets the 3rd column of a matrix A.
A(:,3,5)=*+→Delets the 3rd through 5th column of a matrix A.
A(*1,3+,:)=*+→Delets the 1st and 3rd row of a matrix A.
A(:,*1,3+)=→Delets the 1st and 3rd column of a matrix A.
Sample example:>> Q=[1 2 3 4 5;5 4 3 2 1;4 5 6 7 8;3 4 5 6 6;1 3 5 8 9]
Q=1 2 3 4 5
5 4 3 2 1
4 5 6 7 8
3 4 5 6 6
1 3 5 8 9
>>Q(v,:)
ans = 1 2 3 4 5
3 4 5 6 6
1 3 5 8 9
>>Q(:,v)
ans = 1 4 5
5 2 1
4 7 8
3 6 6
1 8 9
**Reshaping matrix(as a vector):Write a matlab command s.t all
the element of a matrix A can be strung into single column vector b.
Ex:>> A=ones(2)
A=1 1
1 1
>> b=A(:)
b=1
1
1
1
* **As a differently sized matrix: If matrix A is an m×n matrix it can
be reshaped into p×q matrix as long as m×n=p×q ,with the command
reshape (a,p,q).
**Example: Transform a 6×6 matrix A into a 9×4 or 3×12 matrix .
Ans:>> A=ones(6)
A=1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
>>reshape(A,9,4)
ans = 1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Similarly>> reshape (A,3,12)
Transpose:
1)B=A’ produces B=AT if A is a real matrix
2)B=A’ produces B=AT if A is a real complex matrix.
**Utility matrix :
eye(m,n)→returns an m×n matrix with 1st on the main diagonal.
zeros(m,n)→returns an m×n matrix of zeros.
ones(m,n)→returns an m×n matrix of ones.
rand(m,n)→returns an m×n matrix of random numbers.
diag(V)→Generates a diagonal matrix with vector v on the diagonal.
Example: v=[-1 2 4 5 7];
>>diag(v)
ans = -1 0 0 0 0
0 2 0 0 0
0 0 4 0 0
0 0 0 5 0
0 0 0 0 7
** tril(A)→extract the lower triangular part matrix A of a.
**triu(A)→extract the upper triangular part matrix A of a.

*Matrix and array operation :

A+B → is valid if A and B are of same size.


A-B → is valid if A and B are of same size.
A*B → is valid if A number of column equal B number of rows.
A/B → is valid if (and equal A.B-1) for the same size square matrix A and B.
A^2 →makes sense only if A is a square matrix.
A+α(α sclar) →adds αto each element of A.
A*α(α*A) →multiplies of each element of A by α.
Array operation : If u , v are two vectors then,
u.*v → produces element by element multiplication.
u./v → produces element by element division.
u.^v→ produces element by element exponentiation.

***MATRIX FUNCTION :

Exp(A)→ produce a matrix with element e(aij)


Log(A) → produce a matrix with element ln(aij)
Log10(A) → produce a matrix with element Log10A (aij)
Sqrt(A) → produce a matrix with element √Aij
Expm(A) →find eA
Logm (A) → find elog (A)
Sqrt(A) → find √A
Det(A) → find determination of A
Inv(A) → determination of A-1
eig (A) → finds eiagense values of A in a column vector
[eigval,eigvec] =eig (A) → find eigentvectore of A in the matrix eigvec and the
eigvalues of A on the diagonal of the matrix eigval
****Enter the following the three matrices
3 9 , 3 4, 5 3
(1)Compute A+B ,and B+A ,also compare the result .
(2) compute (A+B)+C, A+(B+C) , also A=[2 6] B = [1 2] and C =[ -5 5]
compare the result.
(3) For α=5 , compute α(A+B) and αA+αB , also compare the result.
(4) For α=5 , compute A*(B+C) and A*B+A*C , also compare the result.
(5) For sclersab=ac→b=c if a≠0 is that true for matrix ,cheek by MATLAB .
(A) Computing A*B and A*C
>> A=[2 6;3 9];
>> B=[1 2;3 4];
>> C=[-5 5;5 3];
>> A+B
(1)ans = 3 8
6 13
>> B+A
ans = 3 8
6 13
(2)>> (A+B)+C
ans = -2 13
11 16
>> A+(B+C)
ans = -2 13
11 16
(3)>>alpha=5;
>>alpha*(A+B)
ans = 15 40
30 65
>>alpha*A+alpha*B
ans = 15 40
30 65
(4)>> A*(B+C)
ans = 40 56
60 84
>> A*B+A*C
ans = 40 56
60 84
(6)>> A*B
ans = 20 28
30 42
>> A*C
ans = 20 28
30 42
******Creat the following matrix with the help of matrix generation functions
zeros ,eye and ones
D= 0 0 0
0 0 0,
E= 5 0 0
0 5 0
0 0 5
F= 3 3
3 3
>>zeros(2,3)
ans = 0 0 0
0 0 0
>> E=5*eye(3)
E=5 0 0
0 5 0
0 0 5
>> F=3*ones(2)
F= 3 3
3 3

****Creat a 10× 10 random matrix G .then


(1) Delet the last row and last column .
(2) Extract the first 4× 4 submatrix from G
(3) Replace G(5,5) with 4
(4) what do you get if you type G (13) and hit return
(5) what happen if you type G (12,1)=1 and hit return.
Ans: |
(1)>> G=rand(10,10)
G = 0.8147 0.1576 0.6557 0.7060 0.4387 0.2760 0.7513 0.8407 0.3517 0.0759
0.9058 0.9706 0.0357 0.0318 0.3816 0.6797 0.2551 0.2543 0.8308 0.0540
0.1270 0.9572 0.8491 0.2769 0.7655 0.6551 0.5060 0.8143 0.5853 0.5308
0.9134 0.4854 0.9340 0.0462 0.7952 0.1626 0.6991 0.2435 0.5497 0.7792
0.6324 0.8003 0.6787 0.0971 0.1869 0.1190 0.8909 0.9293 0.9172 0.9340
0.0975 0.1419 0.7577 0.8235 0.4898 0.4984 0.9593 0.3500 0.2858 0.1299
0.2785 0.4218 0.7431 0.6948 0.4456 0.9597 0.5472 0.1966 0.7572 0.5688
0.5469 0.9157 0.3922 0.3171 0.6463 0.3404 0.1386 0.2511 0.7537 0.4694
0.9575 0.7922 0.6555 0.9502 0.7094 0.5853 0.1493 0.6160 0.3804 0.0119
0.9649 0.9595 0.1712 0.0344 0.7547 0.2238 0.2575 0.4733 0.5678 0.3371
(2)>>G(1:9,1:9)
ans = 0.8147 0.1576 0.6557 0.7060 0.4387 0.2760 0.7513 0.8407 0.3517
0.9058 0.9706 0.0357 0.0318 0.3816 0.6797 0.2551 0.2543 0.8308
0.1270 0.9572 0.8491 0.2769 0.7655 0.6551 0.5060 0.8143 0.5853
0.9134 0.4854 0.9340 0.0462 0.7952 0.1626 0.6991 0.2435 0.5497
0.6324 0.8003 0.6787 0.0971 0.1869 0.1190 0.8909 0.9293 0.9172
0.0975 0.1419 0.7577 0.8235 0.4898 0.4984 0.9593 0.3500 0.2858
0.2785 0.4218 0.7431 0.6948 0.4456 0.9597 0.5472 0.1966 0.7572
0.5469 0.9157 0.3922 0.3171 0.6463 0.3404 0.1386 0.2511 0.7537
0.9575 0.7922 0.6555 0.9502 0.7094 0.5853 0.1493 0.6160 0.3804
(3)>>G(5,5)=4
G = 0.8147 0.1576 0.6557 0.7060 0.4387 0.2760 0.7513 0.8407 0.3517 0.0759
0.9058 0.9706 0.0357 0.0318 0.3816 0.6797 0.2551 0.2543 0.8308 0.0540
0.1270 0.9572 0.8491 0.2769 0.7655 0.6551 0.5060 0.8143 0.5853 0.5308
0.9134 0.4854 0.9340 0.0462 0.7952 0.1626 0.6991 0.2435 0.5497 0.7792
0.6324 0.8003 0.6787 0.0971 4.0000 0.1190 0.8909 0.9293 0.9172 0.9340
0.0975 0.1419 0.7577 0.8235 0.4898 0.4984 0.9593 0.3500 0.2858 0.1299
0.2785 0.4218 0.7431 0.6948 0.4456 0.9597 0.5472 0.1966 0.7572 0.5688
0.5469 0.9157 0.3922 0.3171 0.6463 0.3404 0.1386 0.2511 0.7537 0.4694
0.9575 0.7922 0.6555 0.9502 0.7094 0.5853 0.1493 0.6160 0.3804 0.0119
0.9649 0.9595 0.1712 0.0344 0.7547 0.2238 0.2575 0.4733 0.5678 0.3371

(4)>>G(13)
ans = 0.9572

(5)>>G(12,1)=1
G = 0.8147 0.1576 0.6557 0.7060 0.4387 0.2760 0.7513 0.8407 0.3517 0.0759
0.9058 0.9706 0.0357 0.0318 0.3816 0.6797 0.2551 0.2543 0.8308 0.0540
0.1270 0.9572 0.8491 0.2769 0.7655 0.6551 0.5060 0.8143 0.5853 0.5308
0.9134 0.4854 0.9340 0.0462 0.7952 0.1626 0.6991 0.2435 0.5497 0.7792
0.6324 0.8003 0.6787 0.0971 4.0000 0.1190 0.8909 0.9293 0.9172 0.9340
0.0975 0.1419 0.7577 0.8235 0.4898 0.4984 0.9593 0.3500 0.2858 0.1299
0.2785 0.4218 0.7431 0.6948 0.4456 0.9597 0.5472 0.1966 0.7572 0.5688
0.5469 0.9157 0.3922 0.3171 0.6463 0.3404 0.1386 0.2511 0.7537 0.4694
0.9575 0.7922 0.6555 0.9502 0.7094 0.5853 0.1493 0.6160 0.3804 0.0119
0.9649 0.9595 0.1712 0.0344 0.7547 0.2238 0.2575 0.4733 0.5678 0.3371
0 0 0 0 0 0 0 0 0 0
1.0000 0 0 0 0 0 0 0 0 0

Gaussian elimination method:


In introductory linear algebra courses ,we learn to solve a system of algebraic
equation by Gaussian elimination, this technique requires forming a rectangular
matrix that contains both the co efficient matrix A and the know vector b is an
augmented matrix.
Gauss Jordan reduction is then used to transformed the augmented matrix to the
so called row reduce echelon form. MATLAB has a built in function ,rrefdoes
thatprecisely this reductionI, e . transform the matrix to its row reduced echelon
form.
 Solve the following system of,By linear equation gauss Jordan method.

5x-3y+2z=10; -3x+8y+4z=20; 2x+4y-9z=9;

Soln:

>>A=[5 -3 2;-3 8 4;2 4 -9 ];

>>b=[10;20;9];

>>X=[x;y;z];

>> X=inv(A)*b

X=

3.4442
3.1982
1.1868
***By using left division :

>>X=A\b
X =3.4442
3.1982
1.1868
By using gauss Jordan elimination:
>> c=[A b];
>> g=rref(c)
g =1.0000 0 0 3.4442
0 1.0000 0 3.1982
0 0 1.0000 1.1868
By using creamers rule:

>>A(1:3,1)=b
A = 10 -3 2
20 8 4
9 4 -9
>>A1=A;
>>A=[5 -3 2;-3 8 4;2 4 -9 ];
>>x=det(A1)/det(A)
x =3.4442
A(1:3,2)=b
A = 5 10 2
-3 20 4
2 9 -9
>>A2=A;
>>A=[5 -3 2;-3 8 4;2 4 -9 ];
>>y=det(A2)/det(A)
y = 3.1982
>>A(1:3,3)=b
A = 5 -3 10
-3 8 20
2 4 9

>>A3=A;
>>A=[5 -3 2;-3 8 4;2 4 -9 ];
>>z=det(A3)/det(A)
z = 1.1868

If a=(1 2 ;4 -3) and f(x)=2x3-4x+5 then find f(A).


Solution:
>> A=[1 2;4 -3];
>> g=2*A^3-4*A+5*eye(2)
g = -13 52
104 -117

2-D GRAPHICS
Plot(x,y)-Plots y vs x with a solid line.
Plot(x,y,’--’)-Plots y vs x with a dashed line.
Plot(x)-Plots the elements of x against their row index.

***Style line: The style option in the plot command is a character string
that consists of 1,2
or character specify the color and the line style. There are several color,
line and marker
style option.

Color style Line style Marker style


option option option
Y for yellow - for solid + for plus sign
R for red -- for dashed 0 for circle
M for : for doted * for asterisk
magenta
C for cyon -. For dash-dot . for point
G for green X for xmark
B for blue ^ for uptringle
W for white S for square
K for black D for diamond

***The style option is made up of either the color option, the line style
option or a combination of the two.
Examples:
1)Plot(x,y,’r’)-plot y vs x with a red solid line.
2)Plot(x,y,’:’)-Plot y vs x with a doted line.
3)Plot(x,y,’b--’)-Plot y vs x with a blue-dashed line.
4)Plot(x,y,’+’)-Plot y vs x unconnected points marked by +.

Label ,title,legend and other object:


xlabel→-annotates the x-axis.
ylabel→-annototes the y-axis.
title→(‘put a title on the plot’)
legend→(‘mark the several graph’)

***Plot y1=sin(t),y2=t, y3=t-t3/3!+t5/5!


Do the plot using line command.

Solution:

>> t=linspace(0,2*pi,100);
>> y1=sin(t);
>> y2=t;
>> y3=t-(t.^3)/6+(t.^5)/120;
>>plot(t,y1)
>>line(t,y2,'linestyle','--')
>>line(t,y3,'marker','o')
>>axis([0 5 -1 5])
>>xlabel('t')
>>ylabel('approximations of sin(t)')
>>title('graph of sin(t)')

Graph:
fun with sin(t)
5

4
approximations of sin(t)

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t

Figure:line command

***f(t)=tsint, 0≤t≤10п using fplot.


Solution:
t=linspace(0,10*pi,200);
>>fplot('t.*sin(t)',[0 10*pi])
>>xlabel('X');
>>ylabel('Y');
>>title('graph of fplot')

Graph:
graph of fplot
30

20

10

0
Y

-10

-20

-30
0 5 10 15 20 25 30
X

***Using semilogs: y=e-t ,x=0≤t≤2п


Solution:
>> t=linspace(0,2*pi,100);
>>x=exp(-t);
>>y=t;
>>semilogx(x,y), grid
>>xlabel('X');
>>ylabel('Y');
>>title('graph of semilogx')
Graph:
graph of semilogx
7

4
Y

0
-3 -2 -1 0
10 10 10 10
X

***r=2sin5t, 0≤t≤2п using polar command.


Solution:
>>t=linspace(0,2*pi,100);
>>r=sqrt(abs(2*sin(5*t)))
>>polar(t,r)
>>xlabel('x');
>>ylabel('Y');
>>title('graph of polar command')
Graph:
graph of ploar
90 1.5
120 60

150 30
0.5

180 0
Y

210 330

240 300
270

***r=2sin5t,o≤t≤2п using fill command.


Where x=rcost, y=rsint
>> t=linspace(0,2*pi,200);
>> r=sqrt(abs(2*sin(5*t)));
>> x=r.*cos(t);
>> y=r.*sin(t);
>>fill(x,y,'k');
>>axis('square')
>>xlabel('X axis');
>>ylabel('Y axis');
>>title('graph of fill')
Graph:
graph of fill
1.5

0.5
Y axis

-0.5

-1

-1.5
-1.5 -1 -0.5 0 0.5 1 1.5
X axis

title(‘fun with sin(t)’); Title-put a title on a plot.


Text-write ‘text’ at the location (x,y) in the plot coordinates.
Legend-

Axis control:
1) Axis([-5 10 2 2])-sets the x-axis from-5 to 10 as y-axis from 2 to2.
2) Axis([-5 10 –infinf])-sets the x-axis limit at -5to 10 and the y-axis limit
set automatically.
***OVERLAY PLOT
The command to generate overlay plots:
Plot y1=sint,y2=t and y3=t-t3/3!+t5/5!
Solution:
>> t=linspace(0,2*pi,100);
>> y1=sin(y);
>> y1=sin(t);
>> y2=t;
>> y3=t-(t.^3)/6+(t.^5)/120;
>>plot(t,y1,t,y2,'--',t,y3,'o')
>>axis([0 5 -2 5])
>>xlabel('t')
>>ylabel('approximation of sin(t)')
>>title('fun with sin(t)')
>>text(3.5,0,'sin(t)')
>>gtext('linear approximation')
>>gtext('first 3 terms')
>>gtext('in taylor series')
Graph:

fun with sin(t)


5

3
approximation of sin(t)

0 sin(t)

-1

-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t

***Plot y1=sint,y2=t and y3=t-t3/3!+t5/5!


Do the plot using colour line command.

Solution:

>> t=linspace(0,2*pi,200);
>> y1=sin(t);
>> y2=t;
>> y3=t-(t.^3)/6+(t.^5)/120;
>>plot(t,y1)
>>plot(t,y1,t,y2,'r',t,y3,'k')
>>axis([0 5 -1 5])
>>title('fun with sin(t)')
>>text(3.5,0,'sin(t)')
>>gtext('linear approximation')
>>gtext('first 3 terms')
>>gtext('in taylor series')

Graph:
fun with sin(t)
5

3
linear approximation

0 sin(t)

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

***Do the same using ‘hold’ command:


>> t=linspace(0,2*pi,100);
>> y1=sin(t);
>>plot(t,y1);
>> hold on
>> y2=t;
>>plot(t,y2,'y');
>> y3=t-(t.^3)/6+(t.^5)/120;
>>plot(t,y3,'g');
>>axis([0 5 -1 5]);
>>xlabel('t');
>>ylabel('approximation of sin(t)');
>>title('graph of hold function')
>> hold off
Graph:
graph of hod function
5

4
approximation of sin(t)

-1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t

***r=2sin5t,o≤t≤2п using bar command.


Solution:

>> t=linspace(0,2*pi,200);
>> r=sqrt(abs(2*sin(5*t)));
>> x=r.*cos(t);
>> y=r.*sin(t);
>>bar(t,y)
>>axis([0 pi 0 inf])
>>xlabel('X axis');
>>ylabel('Y axis');
>>title('graph of bar command')
Graph:
graph of bar command
1.4

1.2

0.8
Y axis

0.6

0.4

0.2

0
0 0.5 1 1.5 2 2.5 3
X axis

***worlds population by continents by using barh command.

Solution:

>>cont=char('Asia','Europe','Africa','N.America','S.America');
>>pop=[3332;696;694;434;307];
>>barh(pop)
>>for i=1:5;
>>gtext(cont(i,:));
End
>>xlabel('population');
>>ylabel('Asia,Europe,Africa,N.America,S.America');
>>title('graph of bar command')

Graph:
graph of bar command

5
Asia,Europe,Africa,N.America,S.America

0 500 1000 1500 2000 2500 3000 3500


population

***worlds population by continents by using pie command.

Solution:
>>cont=char('ASia','Europe','Africa','N.America','S.America');
>>pop=[3332;696;694;437;307];
>>pie(pop)
>>for i=1:5,
>>gtext(cont(i,:));
end
>>xlabel('Poplution');
>>ylabel('country');
>>title('graph of world')

Graph:

6%

8%
Europe

Africa

13%
N.America

ASia

S.America
61%
13%

3-D Graphics Plot

***plot a parametric space curve.


X(t)=t, y(t)=t2, z(t)=t3;0<=t<=1.

Solution:
>> t=linspace(0,1,100);
>> x=t;
>> y=t.^2;
>> z=t.^3;
>> plot3(x,y,z),grid
>>xlabel('x(t)=t')
>>ylabel('y(t)=t2')
>>zlabel('y(t)=t3')
>>xlabel('axis X');
>>ylabel('axis Y');
>>zlabel('axis Z');
>>title('graph of parametric space curve')

Graph:
graph of parametric space curve

0.8

0.6
axis Z

0.4

0.2

0
1
1
0.8
0.5 0.6
0.4
0.2
axis Y 0 0
axis X

***Do the problem by using surf command.


Z=cosxcosy e-√(x2+y2)/4 ; ‖x‖ 5; ‖y‖ 5.

Solution:
>> u=-5:.2:5;
>> [X,Y]=meshgrid(u,u);
>> Z=cos(X).*cos(Y).*exp(-sqrt(X.^2+Y.^2)/4);
>>surf(X,Y,Z)
>>xlabel('asxis X');
>>ylabel('axis Y');
>>zlabel('axis Z');
>>title('graph of surf command')
Graph:
graph of surf command

0.5
axis Z

-0.5
5
5
0
0

axis Y -5 -5
asxis X

**Do the problem by using surfc command.


z=cosxcosy e-√x2+y2/4 ; ‖x‖≤5; ‖y‖≤5.
Solution:
>> u=-5:.2:5;
>>[X,Y]=meshgrid(u,u);
>>Z=cos(X).*cos(Y).*exp(-sqrt(X.^2+Y.^2)/4);
>>surfc(Z)
>>xlabel('axis X');
>>ylabel('axis Y');
>>zlabel('axis Z');
>>title('graph of surfc command');
Graph:
graph of surfc command

0.5
axis Z

-0.5
60
60
40
40
20
20

axis Y 0 0
axis X

**Do the problem by using surfl command.


z=cosxcosy e-√x2+y2/4 ; ‖x‖≤5; ‖y‖≤5.

Solution:
>> u=-5:.2:5;
>> u=-5:.2:5;
>> [X,Y]=meshgrid(u,u);
>> Z=cos(X).*cos(Y).*exp(-sqrt(X.^2+Y.^2)/4);
>>surfl(Z)
>>xlabel('axix X');
>>ylabel('axis Y');
>>zlabel('axis Z');
>>title('graph of surfl command')
Graph:
graph of surfl command

0.5
axis Z

-0.5
60
60
40
40
20
20

axis Y 0 0
axix X

***Do the problem using mesh command.


z =-5/1+x2+y2 ; ‖x‖ 3 ;‖y‖ 3.

Solution:
>> x=linspace(-3,3,50);
>> y=x;
>> [x,y]=meshgrid(x,y);
>> z=-5./(1+(x.^2)+(y.^2));
>>mesh(z)
>>xlabel('axis X');
>>ylabel('axis Y');
>>zlabel('axis z');
>>title('graph of mash command')
Graph:
graph of mash command

-1

-2
axis z

-3

-4

-5
60
50
40
40
30
20 20
10
axis Y 0 0
axis X

***Do the problem using mesh(z) command.


Z=sin2x+sin2y ; ‖x‖ π/2 , ‖y‖ π/2.
Solution:
>> x=linspace(-3,3,50);
>> y=x;
>> [x,y]=meshgrid(x,y);
>> z=sin(x.^2)+sin(y.^2);
>>meshz(x,y,z)
>>view(-37.5,50)
>>xlabel('axis X');
>>ylabel('axis Y');
>>zlabel('axis Z');
>>title('graph of meshz command')
Graph:

graph of meshz command

1
axis Z

-1

-2
3
2
4
1
2
0
-1 0
-2 -2
axis Y -3 -4 axis X

***Do the problem using waterfall command.


z =-5/1+x2+y2 ; ‖x‖≤3 ;‖y‖≤3.

Solution:
>> x=linspace(-3,3,50);
>> y=x;
>> [x,y]=meshgrid(x,y);
>> z=-5./(1+x.^2+y.^2);
>>waterfall(z)
>> hidden off
>>xlabel('axis X');
>>ylabel('axis Y');
>>zlabel('axis z');
>>title('graph of waterfall command')
>>

Graph:
graph of waterfall command

-1

-2
axis z

-3

-4

-5
60
50
40
40
30
20 20
10
axis Y 0 0
axis X

CALCULAS

Mathematical operation MATLAB command


Lim f(x) Limit (f)
x→0
Lim f(x) Limit (f,a) or limit (f,x,a)
x→a
Lim f(x) Limit(f,x,a,’left’)
x→a-
Lim f(x) Limit (f,x,a,’right’)
x→a+

***Find lim x/‖ ‖


x→0
Solution:
>>syms x
>> f=x/abs(x);
>> a=0;
>> limit(x/abs(x))
ans =NaN
>> LHL=limit(f,x,a,'left')
LHL =-1
>> RHL=limit(f,x,a,'right')
RHL =1

***Test within the limit of 1/x at x=0 esist or not.


Solution:
>>syms x
>> LHL=limit(1/x,x,0,'left')
LHL =-Inf
>> RHL=limit(1/x,x,0,'right')
RHL =Inf

***limx+cosx/x
x→α
Solution:
>>syms x
>> f=(x+cos(x))/x;
>> LHL=limit(f,x,inf,'left')
LHL =1
>> RHL=limit(f,x,inf,'right')
RHL =1
***lim x2+sin5x/7x
x→-1
Solution:
>>syms x
>> f=(x^2+sin(5*x))/7*x;
>> LHL=limit(f,x,-1,'left')
LHL =sin(5)/7 - 1/7
>> RHL=limit(f,x,-1,'right')
RHL =sin(5)/7 - 1/7

***lim√(1+x)-1/x
x→0
solution:
>>syms x
>> f=(sqrt(1+x)-1)/x;
>> LHL=limit(f,x,0,'left')
LHL =1/2
>> RHL=limit(f,x,0,'right')
RHL =1/2

***lim 1/5+e(1/x-2)
x→2
Slution:
>>syms x
>> f=1/(5+exp(1/x-2));
>> LHL=limit(f,x,2,'left')
LHL =1/(1/exp(3/2) + 5)
>> RHL=limit(f,x,2,'right')
RHL =1/(1/exp(3/2) + 5)
***Piece wise function: A function f(x) is defined as follows

f(x)={

Solution:
>>syms x
>> LHL=limit(x^2,x,1,'left')
LHL =1
>> RHL=limit(x^2+2,x,1,'right')
RHL =3
LHL and RHL are not equal .so the limit does not exist.

***A function f(x) is defined as a follows

F(x)={

Test whether limit of f(x) at x=0, x=1 exist.


Solution:
>>syms x
For x=0,
>> LHL=limit(x^2+1,x,0,'left')
LHL =1
>> RHL=limit(x,x,0,'right')
RHL =0
LHL and RHL are not equal .so the limit does not exist.
For x=1,
>> LHL=limit(x,x,1,'left')
LHL =1
>> RHL=limit(1/x,x,1,'right')
RHL =1
LHL and RHL are equal .so the limit does exist.
DIFFERENTIABILITY
Normal command MATLAB command
F(x), x=0 Limit(f(x),0)
( ) ( ) Limit((f(x+h)-f(x))/h,h,0)
F’(x)=lim
h→0
( ) ( ) ( ) Limit((f(x+h)-2f(x)+f(x-h))/h^2,h,0)
F’’(x)=lim
h→0

***Simplify with first principle:


F(x)=cosx.
solution:
>syms x h
>>limit((cos(x+h)-cos(x))/h,h,0)
ans =-sin(x)

***Simplify with first principle


F(x)=-tanx
solution:
>>syms x h
>>limit((tan(x+h)-tan(x))/h,h,0)
ans =tan(x)^2 + 1

***Deravitave of constant:
**sin5t
Solution:
>>syms s t
>> f=sin(s*t)
>>diff(f,t)
ans =s*cos(s*t)

**sin(ax+b)
Solution:
>>syms a x b
>> f=sin((a*x)+b)
f =sin(b + a*x)
>>diff(f)
ans =a*cos(b + a*x)

INTEGRATION
Normal command MATLAB command
n
∫ dx Int(x^n) or int(x^n,x)
∫ ( ) dx Int(f,a,b) or int(f,x,a,b)
∫ ( ) dx Int(f) or int(f,x)

*** Find maxima & minima of a function :


**Find maxima & minima of
f(x)=2x3 -15x2+36x
Solution:
>>syms x
>> f=2*x^3-15*x^2+36*x;
>> f1=diff(f)
f1 =6*x^2 - 30*x + 36
>>cp=solve(f1)
cp = 2 , 3
>> f2=diff(f,2)
f2 = 12*x – 30
>> x=2;
>> f2=12*x-30
f2 = -6<0 , Which is negative so f(x) is maximum at x=2.
>> x=3;
>> f2=12*x-30
f2 = 6>0 ,which is positive so f(x) is minimum at x=3.
>>f(2)=2*(2^3)-15*(2^2)+36*2
Ans= 28, which is the maximum value.
>>f(3)=2*(3^3)-15*(3^2)+36*3
Ans= 27,which is the minimum value .
*** Find maxima & minima of f(x)=x3-9x2+24x-12
Solution: >>syms x
>> f=x^3-9*x^2+24*x-12;
>> f1=diff(f)
f1 =3*x^2 - 18*x + 24
>>cp=solve(f1)
cp = 2 , 4
>> f2=diff(f1)
f2 =6*x - 18
>> x=2;
>> f2=6*2-18
f2 = -6,which is negative so f(x) is maximum at x=2.
>> x=4;
>> f2=6*4-18
f2 = 6, which is positive so f(x) is minimum at x=4.
>>f(2)=2^3-9*(2^2)+(24*2)-12
F= 8, which is the maximum value.
>>f(4)=4^3-9*(4^2)+24*4-12
f = 4,which is the minimum value .
QQ. Find the inflection point of f(x)=x3-6x2+9x+5
Solution:
>>syms x
>>f=x^3-6*(x^2)+9*x
>> f2=diff(f,2)
f2 =6*x - 12
>>inflectionpt=solve(f2)
inflectionpt= 2
>>double(inflection pt)
ans = 2

DIFFERENTIAL EQUATION
Normal command MATLAB command
D

D2

Dy

D2 y

QQ. Find the inflection point of f(x)=x3-6x2+9x+5


Solution:>>syms x
>> f=x^3-6*(x^2)+9*x+5;
>> f2=diff(f,2)
f2 =6*x - 12
>>inflectionpt=solve(f2)
inflectionpt= 2
>>double(inflectionpt)
ans = 2
***write MATLAB command to solve the following differential
equation.

(1) =1+y2 ,y(0)=1


Solution:>>syms y
>> y=dsolve('Dy=1+y^2','y(0)=1')
y =tan(pi/4 + t)
(2)d2y/dx2+4y=e-2x,y(0)=0,y’(π)=0
Solution:
>>syms x y
>>dsolve('D2y+4*y=exp(-2*x)','y(0)=0','Dy(pi)=0','x')
ans =sin(2*x)/(8*exp(2*pi)) - cos(2*x)/8 - (sin(2*x)*(cos(2*x) -
sin(2*x)))/(8*exp(2*x)) + (cos(2*x)*(cos(2*x) + sin(2*x)))/(8*exp(2*x))

(3)Solve =- ,y(4)=3 also plot the solution curve.


Solution:
>>dsolve('Dy=-(x/y)','y(4)=3','x')
ans =2^(1/2)*(25/2 - x^2/2)^(1/2)
>> x=linspace(0,10,100);
>> y=-(x.^2+25).^(1/2);
>>plot(x,y)
-5

-6

-7

-8

-9

-10

-11

-12
0 1 2 3 4 5 6 7 8 9 10

(4)Solve
Solution:
>>syms x
>>dsolve('Dy=asin(2*x)/(1+(x^2))','y(0)=1','x')
ans =int(asin(2*y)/(y^2 + 1), y = 0..x) + 1

QQ. Find the inflection point of f(x)=x3-6x2+9x+5


Solution:
>>syms x
>> f=x^3-6*(x^2)+9*x+5;
>> f2=diff(f,2)
f2 =6*x - 12
>>inflectionpt=solve(f2)
inflectionpt= 2
>>double(inflectionpt)
ans = 2

***write MATLAB command to solve the following differential


equation.

(1) =1+y2 ,y(0)=1


Solution:
>>syms y
>> y=dsolve('Dy=1+y^2','y(0)=1')
y =tan(pi/4 + t)

(2)d2y/dx2+4y=e-2x,y(0)=0,y’(π)=0
>>syms x y
>>dsolve('D2y+4*y=exp(-2*x)','y(0)=0','Dy(pi)=0','x')
ans =sin(2*x)/(8*exp(2*pi)) - cos(2*x)/8 - (sin(2*x)*(cos(2*x) -
sin(2*x)))/(8*exp(2*x)) + (cos(2*x)*(cos(2*x) + sin(2*x)))/(8*exp(2*x))

(3)Solve =- ,y(4)=3 also plot the solution curve.


Solution:
>>dsolve('Dy=-(x/y)','y(4)=3','x')
ans =2^(1/2)*(25/2 - x^2/2)^(1/2)
>> x=linspace(0,10,100);
>> y=-(x.^2+25).^(1/2);
>>plot(x,y)
-5

-6

-7

-8

-9

-10

-11

-12
0 1 2 3 4 5 6 7 8 9 10

(4)Solve
Solution:
>>syms x
>>dsolve('Dy=asin(2*x)/(1+(x^2))','y(0)=1','x')
ans =int(asin(2*y)/(y^2 + 1), y = 0..x) + 1

THE END

You might also like