Uploaded by Karthikeyan R

Jain Practice

advertisement
CHAPTER 3 MATLAB BASICS
Page 47, 48
> 9+7
ans =
16
>> 9.1-7
ans =
2.1000
>> 2*4
ans =
8
>> 8/3
ans =
2.6667
>> 8\3
ans =
0.3750
>> 5+4/2
ans =
7
>> 5+5/3
ans =
6.6667
>> 2^3
ans =
8
>> 5*5/3
ans =
8.3333
>> 9^(1/3)+16^0.3
ans =
4.3775
>> (5+5)/3
ans =
3.3333
>> 0.325+(0.325^2)/(2*3)+3^2/(2*4)
ans =
1.4676
Page 53 Functions to handle complex numbers
>> x=2+j3
Undefined function or variable 'j3'.
>> x=2+j*3
x =
2.0000 + 3.0000i
>> p=real(x)
p =
2
>> q=imag(x)
q =
3
>> r=conj(x)
r =
2.0000 - 3.0000i
>> m=abs(x)
m =
3.6056
>> theta=angle(x)
theta =
0.9828
>> [theta,m]=cart2pol(p,q)
theta =
0.9828
m =
3.6056
>> [p,q]=pol2cart(theta,m)
p =
2
q =
3.0000
Output Display Formats
>> pi
ans =
3.1416
>> format long
>> pi
ans =
3.141592653589793
>> 291/7
ans =
41.571428571428569
>> format short e
>> pi
ans =
3.1416e+00
>> format short g
>> pi
ans =
3.1416
>> format long e
>> pi
ans =
3.141592653589793e+00
>> format long g
>> pi
ans =
3.14159265358979
>> format bank
>> pi
ans =
3.14
>> format hex
>> pi
ans =
400921fb54442d18
>> format +
>> pi
ans =
+
>> format rat
>> pi
ans =
355/113
>> format short
>> pi
ans =
3.1416
>> R=[155 -150 0;-150 500 -250;0 -150 450];
>> V=[100;0;-50];
>> I=inv(R)*V
I =
0.8911
0.2541
-0.0264
>> p=10
p =
10
>> p=3*p-10
p =
20
>> a=20;
>> b=5*a;
>> c=a+b;
>> c
c =
120
>> a
a =
20
>> b
b =
100
>> R=input('Enter R value in ohm:')
Enter R value in ohm:10
R =
10
>> R=input('Enter R values in brackets: ')
Enter R values in brackets: [10 20 30 40]
R =
10
20
30
40
>> f=input('Frequency in Hz:');
Frequency in Hz:50
>> f
f =
50
Download