Matlab Assignment
Matlab Assignment
+ ln(
)+
Program
-----------var1=17*(sqrt(5)-1)/(15*15-13*13);
var2=power(5,7)*log10(exp(3))/(pi*sqrt(121));
var3=log(exp(4));
var4=sqrt(11);
totalsum=var1+var2+var3+var4;
Output
---------totalsum =
2.9532e+003
Program
-----------mat1=[1:8;9:16;17:24;25:32;33:40];
Output
---------mat1 =
1
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
Program
-----------submat1=mat1([1 3 5],[1 2 4 8]);
Output
----------
submat1 =
1
17 18 20 24
33 34 36 40
b)
4 12 20 28
Columns 13 through 16
6 14 22 30
(x) =
Program
-----------p1=[1 8 5 4 3 2 1 1];
r1=roots(p1);
Output
---------r1 =
-7.3898
-0.6570 + 0.3613i
-0.6570 - 0.3613i
0.4268 + 0.5473i
0.4268 - 0.5473i
-0.0749 + 0.7030i
-0.0749 - 0.7030i
b)
(x) =
Program
-----------p2=[1 -7 7 15 -10 -8 7 15];
r2=roots(p2);
Output
---------r2 =
5.1625
2.4906
0.8961 + 0.6912i
0.8961 - 0.6912i
-1.2191
-0.6131 + 0.6094i
-0.6131 - 0.6094i
c)
Program
-----------p3=[1 -13 10 12 8 -15];
r3=roots(p3);
Output
---------r3 =
12.0867
-0.7057 + 0.7061i
-0.7057 - 0.7061i
1.4875
0.8371
d)
Program
-----------p4=[1 7 12 -25 8];
r4=roots(p4);
Output
---------r4 =
-4.1331 + 2.2411i
-4.1331 - 2.2411i
0.8305
0.4358
e)
Program
g)
Program
-----------p7=[1 7];
r7=roots(p7);
Output
---------r7 = -7
B=
Program
-----------A=[1 0 2;2 5 4;-1 8 7];
B=[7 8 2;3 5 9;-1 3 1];
Output
---------A=
1
-1
-1
B=
a) A+B
Program
-----------var1=A+B;
Output
---------var1 =
8
5 10 13
-2 11
b) AB
Program
-----------var2=A*B;
Output
---------var2 =
5 14
25 53 53
10 53 77
c)
Program
------------
var3=A*A;
Output
---------var3 =
-1 16 16
8 57 52
8 96 79
d) AT
Program
-----------var4=A';
Output
---------var4 =
1
2 -1
e)
Program
-----------var5=inv(B);
Output
---------var5 =
f)
Program
-----------var6=B'*A';
Output
---------var5 =
0.0991 0.0090 -0.2793
0.0541 -0.0405 0.2568
-0.0631 0.1306 -0.0495s
g)
Program
-----------var7=(A*A)+(B*B)+(A*B);
Output
---------var7 =
75 132 108
60 186 165
19 159 182
A=
B=
A=
D=
Program
-----------A=[2 1;0 5;7 4];
B=[5 3;-2 -4];
C=[2 3;-5 -2;0 3];
D=[1 2];
Output
----------
A=
2
B=
5
-2 -4
C=
2
-5 -2
0
D=
1
a) (ACTD)-1
Not possible. Matrix dimensions are not matching.
b) IBI
Program
-----------var1=det(B);
Output
---------var1 =
-14
c) IACTI
Program
-----------var2=det(A*C');
Output
---------var2 =
0
d) (CDA)-1
Not possible. Matrix dimensions are not matching.
A=
B=
6.2832
0 -15.0000i
18.0000
a) A+B
Program
-----------var1=A+B;
Output
---------var1 =
3.0000 + 7.0000i 6.2832 -15.0000i
6.2832 + 5.0000i 28.0000 + 1.4142i
b) AB
Program
-----------var2=A*B;
Output
---------var2 =
1.0e+002 *
0.3948 + 0.2100i 1.1310 - 0.4500i
0.2783 + 0.0889i 2.5500 + 0.2546i
c) A2
Program
-----------var3=A*A;
Output
---------var3 =
9.0000 +31.4159i 81.6814 + 8.8858i
-7.0711 +65.0000i 98.0000 +59.7002i
d) AT
Program
-----------var4=A';
Output
---------var4 =
3.0000
0 - 5.0000i
6.2832
10.0000 - 1.4142i
e)B-1
Program
-----------var5=inv(B);
Output
---------var5 =
0 - 0.0817i 0.0681
0 + 0.0285i 0.0318
f) BTAT
Program
-----------var6=B'*A';
Output
---------var6 =
1.0e+002 *
0.3948 - 0.2100i 0.2783 - 0.0889i
1.1310 + 0.4500i 2.5500 - 0.2546i
g) A2+B2-AB
Program
-----------var7=(A*A)+(B*B)-(A*B);
Output
---------var7 =
1.0e+002 *
-0.7948 - 0.8383i 0.7358 - 2.1611i
0.7819 + 1.0010i 1.6700 - 0.6000i
Q8. If A =
Use matlab to determine the following:
Program
a)
10
var1 =
17.4432
0.2784 + 3.0348i
0.2784 - 3.0348i
b) The
eigen vectors of A.
Program
-----------[V,D] = eig(A);
var2=A*V;
var3=V*D;
Output
---------var2 =
6.4934
10.4178
12.3923
var3 =
6.4934
10.4178
12.3923
c) Show that AQ=Qd ,where Q is the matrix containing the eigen vectors as coluns
and d is the matrix containing tha corresponding eigen values on the main diagonal
and zeros else where.
0.5972
0.7104
0.6362
0.6362
D=
17.4432
0
0
0.2784 + 3.0348i
0
0
0.2784 - 3.0348i
Q9. Determine the eigen values and eigen vectors of the following matrices using
MATLAB:
a)
A=
Program
----------A1=[1 -2;1 3];
[V1,D1] = eig(A1);
Output
---------V1 =
0.8165
0.8165
D1 =
2.0000 + 1.0000i
0
9(b)
2.0000 - 1.0000i
A=
Program
-----------
Output
---------V2 =
0.8452
0.8452
2.5000 + 2.7839i
0
2.5000 - 2.7839i
9(c)
Program
----------A3=[4 -1 5;2 1 3;6 -7 9];
[V3,D3] = eig(A3);
Output
---------V3 =
10.0000
0 0.5858
0 3.4142
A=
9(d)
Program
----------A4=[3 5 7;2 4 8;5 6 10];
[V4,D4] = eig(A4);
Output
---------V4 =
0.5054
0.4893
-0.7177
0.7108
-0.7177
D4 =
17.6859
0
0
9(e)
A=
-0.3430 + 1.0066i
0
-0.3430 - 1.0066i
Program
----------A5=[3 0 2 1;1 2 5 4;7 -1 2 6;1 -2 3 4];
[V5,D5] = eig(A5);
Output
----------
V5 =
0.1953
-0.3325
0.4090
-0.7695
0.7748
-0.7741
-0.5261
0.4420
-0.1433
0.7748
D5 =
-2.6635
6.5954
3.5341 + 1.1341i
0
3.5341 - 1.1341i
9(f)
Program
----------A6=[1 3 5 7;2 -1 -2 4;3 2 1 1;4 1 0 6];
[V6,D6] = eig(A6);
Output
---------V6 =
0.6752
0.8466
0.2650
-0.3291
0.7203
0.3207
-0.2962
0.6092
-0.2952
0.7203
D6 =
10.8684
-4.3563
0.2440 + 0.3308i
0
0.2440 - 0.3308i
Q-10 Determine the values of x,y, and z for the following set of algebraic
equations :
a) 2x + y 3z = 11
4x - 2y + 3z = 8
-2x + 2y z = -6
Program
----------A1=[2 1 -3;4 -2 3;-2 2 -1];
B1=[11 8 -6]';
sol1=inv(A1)*B1;
Output
---------sol1 =
3.0000
-1.0000
-2.0000
10(b)
2x y = 10
x + 2y z = 0
y + z = -50
Program
----------A2=[2 -1 0;-1 2 -1;0 -1 1];
B2=[10 0 -50]';
sol2=inv(A2)*B2;
Output
----------
sol2 =
-40.0000
-90.0000
-140.0000
a) 2x1+x2+x3-x4=12
x1+5x2-5x3+6x4=35
-7x1+3x2-7x3-5x4=7
x1-5x2+2x3+7x4=21
Program
----------A1=[2 1 1 -1;1 5 -5 6;-7 3 -7 -5;1 -5 2 7];
B1=[12 35 7 21]';
sol1=inv(A1)*B1;
Output
---------A1 =
5 -5
-7
3 -7 -5
1 -5
1 -1
B1 =
12
35
7
21
11b) x1-x2+3x3+5x4=7
2x1+x2-x3+x4=6
-x1-x2-2x3+2x4=5
x1+x2-x3+5x4=4
Program
----------A2=[1 -1 3 5;2 1 -1 1;-1 -1 -2 2;1 1 -1 5];
B2=[7 6 5 4]';
sol2=inv(A2)*B2;
Output
---------A2 =
1 -1
1 -1
-1 -1 -2
B2 =
7
6
5
4
1 -1
Program
----------w=15;
x=0:.1:1.5;
y=exp(-0.7*x).*sin(w*x);
plot(y);
Output
----------
Program
-----------
x=0:1:20;
y1=exp(-2*x).*cos(x);
plot(x,y1);
Output
----------
Program
----------y2=exp(2*x);
plot(x,y2);
Output
----------
Program
----------y=cos(x)./x;
plot(y);
Output
----------
Program
----------t=0:1:20;
f=exp(-3*t/5).*cos(t);
plot(f);
Output
----------
Program
----------x=-7:1:7;
y=-7:1:7;
z=((-1/3)*x.*x)+(2*x.*y)+(y.*y);
plot(x,z);
Output
----------
x7, y7
Q-14 Use MATLAB for plotting 3D data for the following function:
(a) z=cos(x)cos(y) exp(-(x2-y2)/2),
x7 , y7
Program
----------x=-7:1:7;
y=-7:1:7;
z=(cos(x)).*(cos(y)).*(exp(-1*sqrt(power(x,2)-power(y,2))/2));
plot3(x,y,z);
Output
----------
14(b)
Program
----------t = linspace(-2*pi,2*pi,10);
z=exp(1)*t/5-2;
h = stem3(t,t.*cos(t),z,'fill','--');
Output
----------
14(c)
Program
----------[x,y,z] = ellipsoid(0,0,0,1,2.5,0.7);
plot3(x,y,z);
Output
----------
14(d)
A cylinder generated by
R=sin(5nz) + 3,
0z1
02n
Program
----------t = 0:pi/10:2*pi;
z=0:.1:1;
[X,Y,Z] = cylinder(sin(5*pi*z)+3);
surf(X,Y,Z);
axis square;
Output
----------
15)
Program
----------[X,Y] = meshgrid(-4:1:4);
temp=-1.5*sqrt(X.*X-Y.*Y);
Z=power(2,temp).*sin(X).*cos(0.5*Y);
Output
---------Function z is defined and assigned values
a) Waterfall Plot
Program
---------waterfall(X,Y,Z);
Output
---------
b) Mesh Plot
Program
---------mesh(X,Y,Z);
Output
---------
c) Surface Plot
Program
---------surf(X,Y,Z);
Output
---------
Output
---------
E)
Output
---------
Output
---------
G)
Output
---------
output
----------------------
Z=
Program
------------------------x=-10:.1:10;
y=-10:.1:10;
z=(-7)./(1-(x.*x)-(y.*y));
plot(z);
output
--------------------------
Q.17. Determine the solutions of the following first order ordinary differential
equations using MATLABs symbolic mathematics.
a)
=8
Program
---------------------r=dsolve('Dy=8*(x^2)+5','y(2)=0.5','x');
output
-----------------------
r =8/3*x^3+5*x-185/6
d)
Program
----------------------
r=dsolve('Dy=-5*x+y','y(0)=3','x');
output
----------------------r =5*x+5-2*exp(x)
e)
Program
---------------------r=dsolve('Dy=3*y+(exp(-5*x))','y(0)=2','x');
output
----------------------r =(-1/8*exp(-8*x)+17/8)*exp(3*x)
Q.18. For the following differential equations, use MATLAB to find x(t) when (a)
all the initial conditions are zero, (b) x(t) when x(0)=1 and dx/dt=-1
a) y "+10y'+5y=11
Program
-----------------------r1=dsolve('D2x+10*Dx+5*x=11','x(0)=0');
r2=dsolve('D2x+10*Dx+5*x=11','x(0)=1');
r3=dsolve('D2x+10*Dx+5*x=11','Dx(0)=-1');
Output
-------------------------r1 =exp((-5+2*5^(1/2))*t)*C2+exp(-(5+2*5^(1/2))*t)*(-C2-11/5)+11/5
r2 =exp((-5+2*5^(1/2))*t)*C2+exp(-(5+2*5^(1/2))*t)*(-C2-6/5)+11/5
r3 =exp((-5+2*5^(1/2))*t)*C2+exp(-(5+2*5^(1/2))*t)*(4*C2*5^(1/2)-9*C2-2/5*5^(1/2)+1)+11/5
b) y"-7y'-3y=5
Program
-----------------------r1=dsolve('D2x-7*Dx-3*x=5','x(0)=0');
r2=dsolve('D2x-7*Dx-3*x=5','x(0)=1');
r3=dsolve('D2x-7*Dx-3*x=5','Dx(0)=-1');
Output
-------------------------r1 =exp(1/2*(7+61^(1/2))*t)*C2+exp(-1/2*(-7+61^(1/2))*t)*(-C2+5/3)-5/3
r2 =exp(1/2*(7+61^(1/2))*t)*C2+exp(-1/2*(-7+61^(1/2))*t)*(-C2+8/3)-5/3
r3 =exp(1/2*(7+61^(1/2))*t)*C2+exp(-1/2*(7+61^(1/2))*t)*(55/6*C2+7/6*C2*61^(1/2)+7/6+1/6*61^(1/2))-5/3
c) y"+3y'+7y= -15
Program
------------------------
r1=dsolve('D2x+3*Dx+7*x=-15','x(0)=0');
r2=dsolve('D2x+3*Dx+7*x=-15','x(0)=1');
r3=dsolve('D2x+3*Dx+7*x=-15','Dx(0)=-1');
Output
--------------------------
r1 =exp(-3/2*t)*sin(1/2*19^(1/2)*t)*C2+15/7*exp(-3/2*t)*cos(1/2*19^(1/2)*t)-15/7
r2 =exp(-3/2*t)*sin(1/2*19^(1/2)*t)*C2+22/7*exp(-3/2*t)*cos(1/2*19^(1/2)*t)-15/7
r3 =exp(-3/2*t)*sin(1/2*19^(1/2)*t)*C2+exp(3/2*t)*cos(1/2*19^(1/2)*t)*(1/3*19^(1/2)*C2+2/3)-15/7
d) y"+7y'+7y=26
Program
-----------------------r1=dsolve('D2x+7*Dx+7*x=26','x(0)=0');
r2=dsolve('D2x+7*Dx+7*x=26','x(0)=1');
r3=dsolve('D2x+7*Dx+7*x=26','Dx(0)=-1');
Output
-------------------------r1 =
exp(1/2*(-7+21^(1/2))*t)*C2+exp(-1/2*(7+21^(1/2))*t)*(-C2-26/7)+26/7
r2 =
exp(1/2*(-7+21^(1/2))*t)*C2+exp(-1/2*(7+21^(1/2))*t)*(-C2-19/7)+26/7
r3 =
exp(1/2*(-7+21^(1/2))*t)*C2+exp(-1/2*(7+21^(1/2))*t)*(1/2*C2*21^(1/2)-5/2*C21/14*21^(1/2)+1/2)+26/7
Program
-----------------syms x;
syms n;
Output
-----------------Symbols x & n are defined
(a)
dx
Program
------------f=(5*x^7)-(x^5)+(3*x^3)-(8*x^2)+7;
res=int(f);
Output
-----------Res= 5/8*x^8-1/6*x^6+3/4*x^4-8/3*x^3+7*x
(b)
Program
-------------f=sqrt(x)*cos(x);
res=int(f);
Output
--------------
res =sin(x)*x^(1/2)-1/2*2^(1/2)*pi^(1/2)*FresnelS(2^(1/2)/pi^(1/2)*x^(1/2))
(c)
Program
---------------f=power(x,(2/3))*sin(22*x);
res=int(f);
Output
--------------res =
1/242*11^(1/3)*pi^(1/2)*(1/6/pi^(1/2)*x^(1/2)*11^(1/2)*2^(5/6)*sin(22*x)*LommelS1(1/6,3/
2,22*x)-1/44/pi^(1/2)/x^(1/2)*11^(1/2)*2^(5/6)*(22*cos(22*x)*xsin(22*x))*LommelS1(7/6,1/2,22*x))
(d
dx
Program
----------------f=(x^2)*sin(x);
res=int(f);
Output
--------------------
res =-x^2*cos(x)+2*cos(x)+2*x*sin(x)
(e)
dx
Program
----------------f=abs(x);
res=int(f);
Output
-------------------res =PIECEWISE([-1/2*x^2, x <= 0],[1/2*x^2, 0 < x])
Q-20
A=
Program
----------------syms s;
A=[3*s 2 0;7*s -1*s -5;3 0 -3*s];
invA=inv(A);
Output
-----------------invA =
[ s^2/(3*s^3+14*s^2-10),
2*s/(3*s^3+14*s^2-10),
-10/3/(3*s^3+14*s^2-10)]
[ (7*s^2-5)/(3*s^3+14*s^2-10),
-3*s^2/(3*s^3+14*s^2-10),
5*s/(3*s^3+14*s^2-10)]
[ s/(3*s^3+14*s^2-10),
2/(3*s^3+14*s^2-10), -1/3*s*(3*s+14)/(3*s^3+14*s^2-10)]
Q-21 Expand the following function F(s) into partial fractions with
MATLAB:
Q-21
F(s)=
Program
----------------b = [5 7 8 30];
a = [1 15 62 85 25];
[r,p,k] = residue(b,a);
Output
----------------[r,p,k]
ans =
8.9278
-4.6370
0.0578
0.6514
-9.2690
-3.2633
-2.0680
-0.3997
Program
--------------------
(b) f(t)=
f=exp(5*t);
sys=laplace(f);
Output
-------------------sys =1/(s-5)
(c) f(t)=5t+7
Program
-------------------f=5*t+7;
sys=laplace(f);
Output
--------------------sys =5/s^2+7/s
(d)=5u(t)+8
-12
Program
-------------------f=5+(8*exp(7*t))-(12*exp(-8*t));
sys=laplace(f);
Output
-------------------
sys =5/s+8/(s-7)-12/(s+8)
(e) f(t)=
+9 -7 +8
Program
-----------------f=exp(-1*t)+(9*t^3)-(7*t^-2)+8;
sys=laplace(f);
Output
----------------sys =1/(1+s)+54/s^4-7*laplace(1/t^2,t,s)+8/s
sys =168/s^5+10/s^3-1/(s+7)
(g) f(t)=9u(t)+5
Program
-----------------f=9+(5*(exp(-3*t)));
sys=laplace(f);
Output
------------------sys =9/s+5/(s+3)
Q-23 Determine the inverse laplace transform of the following function using
MATLABS
(a) F(S) =
Program
------------------f=s/(s*(s+2)*(s+3)*(s+5));
sys=ilaplace(f);
Output
------------------sys =1/3*exp(-2*t)-1/2*exp(-3*t)+1/6*exp(-5*t)
(b) F(S) =
Program
-----------------f=1/(s*s*(s+7));
sys=ilaplace(f);
Output
--------------------
sys =1/7*t-2/49*exp(-7/2*t)*sinh(7/2*t)
(c) F(S) =
Program
---------------f=(5*s+9)/(s^3+(8*s)+5);
sys=ilaplace(f);
Output
---------------sys =1/2723*sum((-1045*_alpha+1104+207*_alpha^2)*exp(_alpha*t),_alpha =
RootOf(_Z^3+8*_Z+5))
(d) F(s) =
Program
---------------f=(s+28)/(s*(s^2+(9*s)+33));
sys=ilaplace(f);
Output
----------------sys =-28/33*exp(-9/2*t)*cos(1/2*51^(1/2)*t)-62/561*51^(1/2)*exp(9/2*t)*sin(1/2*51^(1/2)*t)+28/33