Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
40 views

Assignment 2 MATLAB

This document contains a MATLAB assignment submitted by a student. It includes 10 coding questions and the outputs. The key details are: 1) The assignment contains 10 coding questions involving matrices, loops, complex numbers and other MATLAB functions. 2) For each question, the student's code and the output are provided. 3) The questions cover a range of MATLAB skills including matrices, loops, complex numbers, plotting and other basic functions.

Uploaded by

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

Assignment 2 MATLAB

This document contains a MATLAB assignment submitted by a student. It includes 10 coding questions and the outputs. The key details are: 1) The assignment contains 10 coding questions involving matrices, loops, complex numbers and other MATLAB functions. 2) For each question, the student's code and the output are provided. 3) The questions cover a range of MATLAB skills including matrices, loops, complex numbers, plotting and other basic functions.

Uploaded by

Krishna Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

MATLAB ASSIGNMENT 2

NAME:Krishna Singh ID:2022UEE1133


BATCH:E3

1.(a) Code:
A=magic(3)
x=A(2:3,2:3)

(b) A(3,:)=[]

(C) y=size(A)

(d) w=A(:)

(e) s=A(end,:)

(f) d=diag(A)

WORKSPACE:

OUTPUT:

A=8 1 6
3 5 7
4 9 2

x =5 7
9 2

A=8 1 6
3 5 7

y=2 3

w=8
3
1
5
6
7
s=3 5 7

d=8
5

2.
CODE:
SUM=0
for i=1:100
SUM=SUM+i^2
end
disp(SUM)

WORKSPACE:

OUTPUT: 338350
3.
CODE:
% Find node Voltages.
Y=[0.15 -0.1 -0.05 ; -0.1 0.145 -0.025 ; -0.05 -0.025 0.075]
I=[5 ; 0 ; 2]
V=inv(Y)*I
fprintf('Node Voltages are : \n V1=%3.2f \n V2=%3.2f \n V3=%3.2f', V)

WORKSPACE:

OUTPUT:
Y= 0.1500 -0.1000 -0.0500
-0.1000 0.1450 -0.0250
-0.0500 -0.0250 0.0750
I =5
0
2
V =404.2857
350.0000
412.8571
Node Voltages are :
V1=404.29
V2=350.00
V3=412.86

4.
CODE:
V=10;
A=[40 -30 0 ; 10 5 -15 ; 30 -65 -30];
delta=det(A);
d1=[10 -30 0 ; 0 5 -15 ; 0 -65 -30];
det_d1=det(d1);
d2=[40 10 0 ; 10 0 -15 ; 30 0 -30];
det_d2=det(d2);
d3=[40 -30 10 ; 10 5 0 ; 30 -65 0];
det_d3=det(d3);
I1=det_d1/delta
I=det_d2/delta
I2=det_d3/delta
I3=I1++I2
P=V*I3

WORKSPACE:

OUTPUT:
I1 =0.2778
I = 0.0370
I2 = 0.1975
I3 = 0.4753
P =4.7531
5.
CODE:
z1=(3+j*4)
z2=(5+j*2)
z3=(2*exp(j*(60/180)*pi))
z_3=2*(cos(pi/3)+j*sin(pi/3))
z4=(3+j*6)
z5=(1+2*j)
Z=(z1*z2*z3)/(z4*z5)
[x,y]=pol2cart(angle(Z),abs(Z))
[a,b]=cart2pol(x,y)
clc
clear
z1=(3+j*4)
z2=(5+j*2)
z3=(2*exp(j*(60/180)*pi))
z_3=2*(cos(pi/3)+j*sin(pi/3))
z4=(3+j*6)
z5=(1+2*j)
Z=(z1*z2*z3)/(z4*z5)
[x,y]=pol2cart(angle(Z),abs(Z))
[a,b]=cart2pol(x,y)

WORKSPACE:

OUTPUT:
z1 =3.0000 + 4.0000i
z2 =5.0000 + 2.0000i
z3 =1.0000 + 1.7321i
z_3 =1.0000 + 1.7321i
z4 = 3.0000 + 6.0000i
z5 = 1.0000 + 2.0000i
Z = 3.5546 + 0.5035i
x =3.5546
y = 0.5035
a = 0.1407
b = 3.5901

6.
CODE:
y=zeros(20,1);
y(1)=1;
temp=0;
for n=2:20
temp=1:n ;
y(n)=y(n-1)*sum(temp.^3);
fprintf('%5d \t %0.2f \n ' , n , y(n))
end

WORKSPACE:
OUTPUT:
2 9.00
3 324.00
4 32400.00
5 7290000.00
6 3214890000.00
7 2520473760000.00
8 3266533992960000.00
9 6614731335744000000.00
10 20009562290625601077248.00
11 87161653337965115171930112.00
12 530291498908179791767226286080.00
13 4391343902458636597441478487179264.00
14 48414566524606471201345982917972590592.00
15 697169757954333182277067604982232367759360.00
16 12894851843123346965248015935922184439375855616.00
17 301855586795674419581828893728630233892128112508928.00
18 8826559213492315824741235420443514903022796065426374656.00
19
318638787607072591015686930213241845359158771538671158951936.00
20
1405197053347190110857860704063082831525030264722280202815668224
0.00

7.
CODE:
n=5;
for i=1:n
fprintf('%6d %8.4f \n', i , sqrt(i));
end

WORKSPACE:

OUTPUT:
1 1.0000
2 1.4142
3 1.7321
4 2.0000
5 2.2361

8.
CODE:
r=input('Enter the number of rows:')
for R=1:r;
for s=1:R;
fprintf('*');
end
fprintf('\n');
end

WORKSPACE:

OUTPUT:
r =5

*
**
***
****
*****
9.
CODE:
Sum=0;
for i=2:20;
Sum=Sum+i^2;
%fprintf('%5.2f');
end
disp(Sum);

WORKSPACE:
OUTPUT:
2869

10.
CODE:
Sum=0;
for i=1:10;
Sum=Sum+i^3;
end
disp(Sum)

WORKSPACE:

OUTPUT:
3025

You might also like