Matlab Note: by Abdullah (Student of B S Maths 4 Semester GPG College Timergara Lower Dir) - Date: 9/5/2019
Matlab Note: by Abdullah (Student of B S Maths 4 Semester GPG College Timergara Lower Dir) - Date: 9/5/2019
MATLAB
NOTE
by Abdullah (Student of B S Maths 4th semester GPG
college Timergara lower dir).
Date: 9/5/2019
[email protected]:
1
Dedicated to my Lovely teachers proffessor Adur Rehman
and Murad khan:
2
TABLE OF CONTENTS
1. Basic commonds of matlab........................................4
2. programing in matlab.................................................8
3. Matrix in matlab........................................................10
4. Graphs in matlab.......................................................27
5. Matrix algebra...........................................................52
6. limits , derivatives and integrations.....................56
7.paper of matlab (2019).............................................58
3
1) Basics commonds of matlab:
>> format long g; % it is use for 15 digits after decimal %
>> a=sqrt(78)
a = 8.83176086632785
>> sqrt(78)
ans = 8.8318
>> format long e; % it is use for 15 digit after decimal in exp form %
>> sqrt(78)
ans = 8.831760866327848e+00
>> format short e; % it is use for 4 digit after decimal in exp form %
>> sqrt(78)
ans = 8.8318e+00
>> 1/2
ans = 1/2
>> a=0.5
a = 1/2
4
>> syms a; % it shows that a is arbitrary costant %
>> x=2;
>> y=2*x+a
y=a+4
>> x=0;
>> y=exp((x^2)+2)
y = 7.3891
>> x=4;
>> syms a;
>> y=2*(x^2)+sqrt(x^3)+a
y = a + 40
>> syms x y;
>> f=2*x;
inv = x/2
>> f=2*x^2
inv = (2^(1/2)*x^(1/2))/2
ans = 1
ans = 1.5708
>> a=4.678
5
ans = 4
>> floor(6.77)
ans = 6
>> ceil(78.99)
ans = 79
>> ceil(2.33)
ans = 3
ans = 5
ans = 2 3 13
ans = 2
>> a=gcd(34,56)
a= 2
>> b=gcd(a,67)
b= 1
>> c=gcd(b,35)
c= 1 % gcd of 34,56,67,35 is 1 %
ans = 4
ans = 7.3891e+00
6
>> clc % it clear the commond window %
ans = 7
ans = 2
ans = 24
ans = 12
ans = 1
ans = 4489
>> 8^(1/3)
ans =2
ans = 2
a ans
>> conj(2+3i)
>> c1=complex(2,4)
7
c1 = 2.0000 + 4.0000i
>> c3=sqrt(-2)
c3 = 0.0000 + 1.4142i
c4 = 1.0000 + 5.7071i
c4r = 1
c4im = 5.7071
>> c=2+2i
ans = 2.8284
*************************************************************
2) Programing in matlab:
2.1) Function:
Note: All programes are written in eiditer window and output will be appear in
commond window.
function v = matlab1(a,b,c)
a=input('enter a:')
b=input('enter b:')
c=input('enter c:')
v=(-b)+(sqrt(b^2-4*a*c))/2*a;
disp('the root is ')
end
>> matlab1
enter a:5
8
a=5
enter b:6
b=6
enter c:7
c= 7
the root is
x=input('enter a number');
if rem(x,2)==0
disp('even')
else
disp('odd')
end
out put will be appear in commond window i,e
>> matlab1
enter a number 89
odd
Note: For detial study of progrmming in matlab Read the book "numerical method
with matlab" which is present in class no 519.403 of public library timergara.
*************************************************************
9
3) Matrix in matlab:
2.1) one dimentional matrix:
2.1.1) decleration and acssesing one dimentional
matrix:
>> x=[2 3 4 5] % declearing one dimentional mtarix %
x=2 3 4 5
y=3 5 7 9 11 13 15 17 19 21 23
>> z=[0 pi/4 pi/6 pi/2 2*pi 2*pi/3 2*pi]%declearing one dimentional mtarix%
ans = 6 7 8 9 4 3
ans = 7 6 5
ans = 7 5
ans = 2 4 6 8 10 12 14 16 18 20
10
>> b=[1 2 3 4 5 6 7 8 9];
>> a=(1 : 5)' % it find the transpose of the element from 1 to 5 of matrix a %
a=1
>> c= 1
b=1 2 3 4 5
>> a=[ 1 2 3 ];
e = 1.0000 - 1.0000i
11
2.0000 - 2.0000i
3.0000 - 3.0000i
e = 1.0000 + 1.0000i
2.0000 + 2.0000i
3.0000 + 3.0000i
c= 6 7 8 2 3 4
>> c=a+2
c=4 5 6
>> c=a+b
c =8 10 12
>> d=2*b
d = 12 14 16
>> d=(2*a)+(3*b)
d = 22 27 32
>> d=(2*a)+(3*b)-1
d = 21 26 31
12
ans = 0.3333 0.4286 0.5000
>> 2.^a
ans = 4 8 16
>> a .^2
ans = 4 9 16
ans = 12 21 32
>> max(a)
ans = 4
>> min(b)
ans = 6
ans = 1 1 1
1 1 1
1 1 1
>> zeros(2,3)
ans = 0 0 0
0 0 0
13
>> a=[2,3,4; 3,45,7; 3,4,5; ]
a=2 3 4
3 45 7
3 4 5
ans = 3 3
>> ones(size(a))
ans = 1 1 1
1 1 1
1 1 1
ans = 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> eye(2,4)
ans = 1 0 0 0
0 1 0 0
>> b=1:4
b=1 2 3 4
>> diag(a)
ans = 2
45
14
5
>> diag(b)
ans = 1 0 0 0
0 2 0 0
0 0 3 0
0 0 0 4
>> diag(b,3)
ans = 0 0 0 1 0 0 0
0 0 0 0 2 0 0
0 0 0 0 0 3 0
0 0 0 0 0 0 4
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
>> diag(b,-2)
ans = 0 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 0
0 2 0 0 0 0
0 0 3 0 0 0
0 0 0 4 0 0
a= 2 3 4
3 45 7
15
3 4 5
>> b=[2:1:4; 5:1:7; 8:1:10] % declearing matrix, the 1 st row start from 2 upto 4 and
difference 1 in each elements in the row and samilar for 2nd & 3 rd row %
b=2 3 4
5 6 7
8 9 10
ans = 3
ans = 2
ans = 3
a =2 3 4
3 4 5
6 7 8
b=2 3 6
6 7 8
9 7 2
c=4 6 10
9 11 13
16
15 14 10
c = 58 55 44
75 72 60
-2 1.6667 -0.66667
>> a=[2 3 4; 5 6 7; 2 3 9 ]
a= 2 3 4
5 6 7
2 3 9
ans = 4 8 16
32 64 128
4 8 512
ans = 4 9 16
25 36 49
4 9 81
>> a=[2 3 4; 5 6 7; 2 3 9 ]
a= 2 3 4
5 6 7
17
2 3 9
ans = 4 5 6
7 8 9
4 5 11
ans = 4 6 8
10 12 14
4 6 18
>> a=[2 3 4; 5 6 7; 2 3 9 ]
a= 2 3 4
5 6 7
2 3 9
>> a=[2 3 4; 5 6 7; 2 3 9 ]
a= 2 3 4
5 6 7
2 3 9
b = 2 33 5
3 4 5
18
7 8 9
ans = 4 99 20
15 24 35
14 24 81
>> a=[ 1 2 3; 4 5 6; 7 8 9]
a= 1 2 3
4 5 6
7 8 9
a=1 2 3
4 5 6
7 8 0
>> a=[ 1 2 3; 4 5 6; 7 8 9]
a=1 2 3
4 5 6
7 8 9
a= 1 2 3 0 0 0
4 5 6 0 0 1
7 8 9 0 0 0
a= 1 2 3 4 0 0
4 5 6 4 0 1
19
7 8 9 4 0 0
a= 1 2 3 4 0 0
3 3 3 3 3 3
7 8 9 4 0 0
>> b=a(3:-1:1,1:3)
b=7 8 9
3 3 3
1 2 3
>> a=[ 1 2 3; 4 5 6; 7 8 9]
a= 1 2 3
4 5 6
7 8 9
c=1 2 3 7 9
4 5 6 3 3
7 8 9 1 3
>> c=[ 1 3]
c=1 3
>> b=a(c , c) %b is formed from the first & third rows & first & third columns of a.
b=1 3
7 9
>> b=a(:)
b= 1
20
4
>> c=a(: , :)
c= 1 2 3
4 5 6
7 8 9
c=1 3
4 6
7 9
e= 1 7 6
4 3 9
>> a=[1 2 3; 1 4 7; 7 8 9]
a= 1 2 3
1 4 7
7 8 9
>> reshape(c,3,4)
21
ans = 1 7 4 0
0 4 8 7
1 0 7 9
b= 7 7 7
3 3 3
b= 7 7 7
3 3 3
7 7 7
3 3 3
7 7 7
3 3 3
>> a=[1 2 3; 1 4 7; 7 8 9]
a=1 2 3
1 4 7
7 8 9
>> c=[1 4 7]
c= 1 4 7
>> c(3:4,:)=a(2:3,:)
c=1 4 7
0 0 0
1 4 7
7 8 9
22
>> x=-3:3
x = -3 -2 -1 0 1 2 3
>> abs(x)>1
ans = 1 1 0 0 0 1 1
>> d=x(abs(x)>1)
d = -3 -2 2 3
>> x=[ 7 6 4 3 8 9 3]
>> x=sort(x)
x=3 3 4 6 7 8 9
>> x=sort(x,'descend')
x=9 8 7 6 4 3 3
>> x=sort(x,'ascend')
x=3 3 4 6 7 8 9
ans = 3 7 9
2 4 8
1 1 7
ans = 9 8 7
7 4 1
3 2 1
>> x= -3 : 3
x = -3 -2 -1 0 1 2 3
23
>> k=find(x>2) % it find index no of element of x for x>2 %
k= 7
ans = 3
>> a=[1,2,3;1,4,7;7,8,9]
a=1 2 3
1 4 7
7 8 9
k= 3
ans = 7
>> a=[ 2 3 4 5; 2 3 6 7; 2 1 3 4 ;]
a= 2 3 4 5
2 3 6 7
2 1 3 4
24
ans = 2 3 6 7
ans = 7
ans = 2 1 3 4
ans = 1
a= 1 2 3
4 5 6
7 8 9
>> diag(a)
ans = 1
ans = 1 0 0
0 5 0
0 0 9
ans = 1 2 3
0 5 6
0 0 9
25
>> tril(a) % make lower triangular matrix from matrix a %
ans = 1 0 0
4 5 0
7 8 9
a=3 3
r=2
>> a=[1,0,0;4,5,0;7,8,9]
a= 1 0 0
4 5 0
7 8 9
ans = 3
>> c=[1 2 3 4; 1 2 3 4]
c= 1 2 3 4
1 2 3 4
>> length(c)
ans = 4
x= 4 5
6 7
ans = -2.0000
26
>> rank(x) % it is use for finding no of non zero rows in x %
ans = 2
>> y=[4 5; 0 0]
y= 4 5
0 0
>> rank(y)
ans = 1
******************************************************
4) Graphs in matlab:
3.1)two Dimentional graphs:
3.1.1) The plot funtion:
x=linspace(0,2*pi,30)%create 30 values between 0 to 2*pi%
y=sinx
plot(x,y),title('fiager 3.1: sine wave')
fiager 3.1:sine wave
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
*************************************************************
x=-2:0.005:2
y=sin(1./x)
plot(x,y)
27
title('Graph of sin1/x')
text(0,0,'origin')
Graph of sin1/x
1
0.8
0.6
0.4
0.2
0 origin
-0.2
-0.4
-0.6
-0.8
-1
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
*************************************************************
x=linspace(0,2*pi,30)%create 30 values between 0 to 2*pi%
y=sin(x);
z=cos(x);
plot(x,y,x,z),title('fiager 3.2: sine and cosine')
28
fiager 3.2: sine and cosine
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
*************************************************************
* * x=linspace(0,2*pi,30)%create 30 values between 0 to 2*pi%
y=sin(x);
z=cos(x);
plot(y,x,z,x),title('fiager 3.2: sine and cosine')
0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
29
*************************************************************
x=-6:6
y1=x.^2
plot(x,y1)
title('parabola')
parabola
40
35
30
25
20
15
10
0
-6 -4 -2 0 2 4 6
*************************************************************
t=0:pi/100:2*pi
x=sin(t)
y=cos(t)
plot(x,y)
text(0,0,'origin')
title('circle')
30
circle
1
0.8
0.6
0.4
0.2
0 origin
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
*************************************************************
yellow y square s
black k diamond d
31
triangle up ^
pentagram p
hexagram h
*************************************************************
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,y,'b p',x,z,'c-',x,1.2*z,'m+')
title('fiager 3.3: linestyles and markers')
%the first plot x,y has blue color and pentagram marker
the 2nd plot has cyan color and solid line the 3 rd plot
has magenta color plus singn marker %
fiager 3.3: linestyles and markers
1.5
0.5
-0.5
-1
-1.5
0 1 2 3 4 5 6 7
***********************************************************
x=linspace(0,2*pi,30);
y=sin(x);
32
z=cos(x);
plot(x,y,x,z)
box off %turn off the axis box%
xlabel('independent variable x') %label horizantal axis%
ylabel('dependent variable y and z')%label verticle axis%
title('fiager 3.4: sine and cos curve,no box')
fiager 3.4: sine and cos curve,no box
1
0.8
0.6
dependent variable y and z
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
independent variable x
*************************************************************
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,y,x,z)
box on,grid on %grid mean horizantal & verticle line%
xlabel('independent variable x')
ylabel('dependent variable y and z')
title('fiager 3.4: sine and cos curve,added label')
text(2.5,0.7,'sin(x)')%text function use for label a string
at location 2.5,0.7%
33
fiager 3.4: sine and cos curve,added label
1
0.8
sin(x)
0.6
dependent variable y and z
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
independent variable x
*************************************************************
34
fiager 3.5: sine and cos curve,multiple plots
1.5
1
dependent variable y and z
0.5
-0.5
-1
-1.5
0 1 2 3 4 5 6 7
independent variable x
*************************************************************
x=linspace(0,2*pi,30);
y=sin(x);
z=cos(x);
plot(x,y,'b-',x,z,'k-',x,1.2*z,'g+',x,1.2*y,'r-')
xlabel('independent variable x')
ylabel('dependent variable y and z')
title('fiager 3.5: sine and cos curve,multiple plots')
legend('sin(x)','cos(x)','1.2z','1.2y')
35
fiager 3.5: sine and cos curve,multiple plots
1.5
sin(x)
cos(x)
1 1. 2z
1. 2y
dependent variable y and z
0.5
-0.5
-1
-1.5
0 1 2 3 4 5 6 7
independent variable x
*************************************************************
x=1:30
y=11:40
bar(x,y)
title('bar plot')
xlabel('x-axis')
ylabel('y-axis')
36
bar plot
40
35
30
25
y-axis
20
15
10
0
0 5 10 15 20 25 30
x-axis
*************************************************************
x=[4 5 6 7]
y=[2 6 8 12]
pie(x,y)
title('pie plot')
37
pie plot
18%
32%
23%
27%
*************************************************************
38
fiager 3.6 : sin(x) fiager 3.7: cos(x)
1 1
0.5 0.5
0 0
-0.5 -0.5
-1 -1
0 2 4 6 0 2 4 6
0.5 1
0 0
-0.5 -1
-1 -2
0 2 4 6 0 2 4 6
*************************************************************
3.2) Three dimentional graphs:
3.2.1) Line 3D plots:
t=linspace(0,10*pi)
plot3(sin(t),cos(t),t)
xlabel('sin(t)'),ylabel('cos(t)'),zlabel('t')
text(0,0,0,'0rigin')%fix origin at (0,0,0)%
title('fiager 3.10: helix')
39
fiager 3.10: helix
30
25
20
15
t
10
0
1 0rigin
0.5 1
0 0.5
0
-0.5
-0.5
cos(t) -1 -1 sin(t)
*************************************************************
t=linspace(0,10*pi)
plot3(sin(t),cos(t),t,2*sin(t),2*cos(t),2*t)
xlabel('sin(t)'),ylabel('cos(t)'),zlabel('t')
text(0,0,0'0rigin')
title('fiager 3.10: helix')
grid
40
fiager 3.10: helix
60
50
40
30
t
20
10
0
2 0rigin
1 2
0 1
0
-1
-1
cos(t) -2 -2 sin(t)
*************************************************************
x=-9:9
y=-9:9
z=exp(x.^2+y.^2) %graph of z=f(x,y)%
plot3(x,y,z)
title('fiager 3.11: e^(x^2+y^2)')
grid
41
fiager 3.11: e (x 2+y2 )
10 70
2.5
1.5
0.5
0
10
5 10
0 5
0
-5
-5
-10 -10
*************************************************************
3.2.2) Mesh plots:
mesh(X,Y,Z) draws a wireframe mesh with color determined by Z, so color is
proportional to surface height. If X and Y are vectors, length(X) = n and length(Y) =
m, where [m,n] = size(Z). In this case, (X(j), Y(i), Z(i,j)) are the intersections of the
wireframe grid lines; X and Y correspond to the columns and rows of Z, respectively.
If X and Y are matrices, (X(i,j), Y(i,j), Z(i,j)) are the intersections of the wireframe
grid lines. The values in X, Y, or Z can be numeric, datetime, duration, or categorical
values.
[X,Y]= meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2);
Z = sin(R)./R;
mesh(X,Y,Z)
42
1
0.5
-0.5
10
5 10
0 5
0
-5
-5
-10 -10
*************************************************************
***
x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x,y);
F = X.*exp(-X.^2-Y.^2);
mesh(X,Y,F)
43
0.5
-0.5
2
1 2
0 1
0
-1
-1
-2 -2
*************************************************************
x=-9:9
y=-9:9
z=exp(x.^2+y.^2)%graph of z=f(x,y)%
[x,y,z]=peaks(12)%peaks(12) mean 12 horizantal and verticle
line which make the surface z%
mesh(x,y,z)
title('fiager 3.11: e^(x^2+y^2)')
grid on
44
fiager 3.11: e (x 2+y2 )
-2
-4
4
2 4
0 2
0
-2
-2
-4 -4
rotation of 3.11
3
3
2
2
1
1
0
0
-1
-1
-2 -2
-3 -3
*************************************************************
x=-9:9
45
y=-9:9
z=-9:9
[x,y,z]=peaks(30)
mesh(x,y,z)
title('fiager 3.12: meshplot')
fiager 3.12: meshplot
10
-5
-10
4
2 4
0 2
0
-2
-2
-4 -4
*************************************************************
x=[1.5:0.125:1.5];
y=[-0.6:0.125:2.8];
[x,y,z]=peaks(51);
z=100.*(y-x).*x.^2+(1-x).^2;
meshz(x,y,z)% mesh plot with zero plane%
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
grid on
title('mesh plot with zero plane')
46
mesh plot with zero plane
6000
4000
2000
z-axis
-2000
-4000
-6000
4
2 4
0 2
0
-2
-2
y-axis -4 -4 x-axis
by Abdullah:
*************************************************************
x=[1.5:0.125:1.5];
y=[-0.6:0.125:2.8];
[x,y,z]=peaks(51);
z=100.*(y-x).*x.^2+(1-x).^2;
meshc(x,y,z)
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
grid on
title('mesh plot with contours')
47
mesh plot with contours
4000
2000
z-axis
-2000
-4000
-6000
2
3
2
0 1
0
-2 -1
-2
y-axis -3 x-axis
*************************************************************
3.2.3) Surface plots:
% In surface there is no space beween the gride line which form it or shaded%
x=-9:9
y=-9:9
z=exp(x.^2+y.^2)%graph of z=f(x,y)%
[x,y,z]=peaks(30)
surf(x,y,z)
text(0,0,0,'origen')
title('fiager 3.11: e^(x^2+y^2)')
48
fiager 3.11: e (x 2+y2 )
10
0
origen
-5
-10
4
2 4
0 2
0
-2
-2
-4 -4
*************************************************************
x=-9:9
y=-9:9
z=exp(x.^2+y.^2)%graph of z=f(x,y)%
[x,y,z]=sphere(30)
surf(x,y,z)
text(0,0,0,'origen')
title('fiager 3.11: e^(x^2+y^2)')
49
fiager 3.11: e (x 2+y2 )
0.5
0
origen
-0.5
-1
1
0.5 1
0 0.5
0
-0.5
-0.5
-1 -1
*************************************************************
x=[1.5:0.125:1.5];
y=[-0.6:0.125:2.8];
[x,y,z]=peaks(51);
z=100.*(y-x).*x.^2+(1-x).^2;
surf(x,y,z)
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
grid on
title('surface like banana')
50
surface like banana
6000
4000
2000
z-axis
-2000
-4000
-6000
4
2 4
0 2
0
-2
-2
y-axis -4 -4 x-axis
*************************************************************
x=[1.5:0.125:1.5];
y=[-0.6:0.125:2.8];
[x,y,z]=peaks(51);
z=100.*(y-x).*x.^2+(1-x).^2;
surfnorm(x,y,z) %norm means normals%
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
grid on
title('surface like banana with normals')
51
surface like banana with normals
6000
4000
2000
z-axis
-2000
-4000
-6000
4
2 4
0 2
0
-2
-2
y-axis -4 -4 x-axis
by Abdullah:
*************************************************************
5) Matrix algebra:
4.1) Basic commond of Algebra:
syms x
ans = 10*x
>> x^2+x^2
ans =2*x^2
>> syms x y
>> p=3*x^2;
>> q=2*x^3;
o = 6*x^5
52
>> z=p/q % division of p by q %
z = 3/(2*x)
>>syms x
ans = [ 6, x + 4, x - 1]
>> syms x y
>> F = factor(y^2*x^2,x)
F =[ y^2, x, x]
>> syms x
q = x^2 + 2
r =- 5*x^2 + 4*x - 10
ans =2*x^2
ans =2*x
4.2) Roots:
% roots of a polynomial p(x) is those values of x which give 0 by putting in p(x) %
Note:
In this chapter ploynomial is represented by row matrix of its cofficients in
decending order e,g 2x2+2x-7 can be written is a=[ 2 2 -7];
>> a=[1 2]
53
a= 1 2
>> r=roots(a)
r = -2 % root=-2 %
>> x=-2
x = -2
>> x+2
ans= 0
>> pp=poly(-2)
pp = 1 2 % p(x)= x+2 %
p = 1 -12 0 25 116
>> r=roots(p)
2.7028 + 0.0000i
-1.2251 + 1.4672i
-1.2251 - 1.4672i
>> pp=poly(r)
54
p(x)=x4-11x3+0x2+25x+166
*************************************************************
a=2 3
3 6
>> b=[2; 5]
b=2
>> x=inv(a)*b
x = -1 % x= -1 & y=1.3333 %
1.3333
*************************************************************
>> a=[ 2 3 4; 4 5 6; 8 9 0]
a=2 3 4
4 5 6
8 9 0
>> b=[2; 4; 5]
b=2
>> x=inv(a)*b
55
x = 1.3 % x=1.3, y=-0.6, z=0.3 %
-0.6
0.3
By abdullah.
*************************************************************
>> f=sin(x)/x;
ans = 1
>> syms x;
>> f=1/x;
>> limit(f,x,0,'right') % it find the limit of f when x approches to 0 from the right %
ans = Inf
>> limit(f,x,0,'left') % it find the limit of f when x approches to 0 from the left %
ans = -Inf
>> syms x;
>> f=(abs(x))/x;
>> f=limit(f,x,1)
f=1
>> syms y;
>> f=abs(y)/sin(y);
>> f=limit(f,y,1)
f = 1/sin(1)
56
>> syms n;
>> f=(factorial(n))/n^(n);
>> f=limit(f,n,inf)
f=0
5.2) derivatives:
>> syms x;
>> f=sin(x^2);
f = 2*x*cos(x^2)
f2 = 4*cos(4)
>> syms x t
ans = t^2*cos(t^2*x)
ans = 2*t*x*cos(t^2*x)
>> syms t
d4 = 360*t^2
>> syms x y
ans = -x^3*cos(x*y)
5.3) integrations:
>> syms x; % it use for symbol %
>> f=sin(x);
57
>> F=int(f,x) % it find integration of f w.r.t x %
F = -cos(x)
F = cos(2) - cos(4)
F=0
*************************************************************
b) take the transpose of the first and multiply it with the other element wise.
a) Derivative of 6x2+18x-24.
b) Factorization of 6x2+18x-24.
c) lim x to 0 x/|x|=1.
with examples.
Q5. Write a short script/program that compute a number is even or odd in matlab.
x=input('enter a number');
if rem(x,2)==0
disp('even')
else
disp('odd')
58
end
out put will be appear in commond window i,e
>> matlab1
enter a number 89
odd
*************************************************************
The end
by Abdullah (Student of B S Maths 4th semester GPG college
Timergara lower dir).
Refrences:
1)Book name "Mastering with matlab"
Author name "Duane Hanselman"
2)Book name "Numerical methods with Matlab"
the above books is persent in 'English section' of public
library timergara at class no '519.403'.
date: 9/5/2019
[email protected]:
59
*hj****hggjkghjhjhjkhjkjkhjkhjkhkghghjghjghjjjjjjjjtrianglejjjkjkjkjljl
mncvbncbcbcvnxbvhjhknmbnmcbnbnb>> x=linespace(0,2*pi,30)
>> x=linspace(0,2*pi,30)
x=
Columns 1 through 10
Columns 11 through 20
Columns 21 through 30
60
>> x=linspace(0,2*pi,30);
>> y=sin(x);
>>
>>
>
61
62
63
64
65
66