Uploaded by Mohannad Mohamed

Document (4)

advertisement
1-who: prints all variables in the memory;
Whos: print all variables in the memory with size,type;
Clear: clears all variables in the memory;
Clc: cleaning the command window;
2-Write a MATLAB program (m-file) to print out your name, your address, and your phone number?
name = input('enter your name: ','s');address = input('enter your address: ','s');
phone = input('enter your phone: ','s');disp('name');disp(name);disp('address');disp(address);disp('phone');
disp(phone);
3-Write a MATLAB program (one program) to compute and print out the area of each of the following:
Square, Triangle and Circle
l = input('enter square side lenght: ');disp('area of square');disp(l*l);r = input('enter r of the circle');
disp('area of circle');disp(pi * r^2);
side1 = input('enter first side in triangle:');side2 = input('enter second side in triangle:');
side3 = input('enter third side in triangle:');s = (side1 + side2 + side3) / 2;
areaOfTriangle = sqrt(s*(s-side1)*(s-side2)*(s-side3));disp('area of trirangle');disp(areaOfTriangle);
4- For the following MATLAB program, A=[2, 4, 6, 8, 10]; B=[1, 4, 5, 8, 9]; C=A==B; D=A~=B; E= A>B; F=A
A = [2,4,6,8,10];B = [1,3,5,7,9];C = A==B;D = A~=B; E = A>B;F = A<B;disp(C);disp(D);disp(E);disp(F);
5- For the following MATLAB program, A=6; B=18; C=A/B; D=A\B; E=[2 3 5 7 8 9]; X=0; Y=1; U= (X&Y); V=
(Y|X); W=xor(X,Y); F=any(E); G=all(E); H=~B; What is the value of each of the following variables? C, D, U,
V, W, F, and G
A=5;B=18;X=0;Y=1;E=[2,3,5,7,8,9];C = A/B;D = A\B;U = (X&Y);V = (X|Y);W = xor(X,Y);F = any(E);G = all(E);H =~B;
disp('C');disp(C);disp('D');disp(D);disp('U');disp(U);disp('V');disp(V);disp('W');disp(W);disp('F');disp(F);
disp('G');disp(G);disp('H');disp(H);
6- For the following MATLAB program, A=1; B=0; C=0; D=9; E=3; X=A&B|C; Y=A|B&C; Z= D/E+A&B|C *E;
W= D/E+A|B&C *E;
A=1; B=0; C=0; D=9; E=3; X=A&B|C; Y=A|B&C; Z= D/E+A&B|C *E;
W= D/E+A|B&C *E;disp(X);disp(Y);disp(Z);disp(W);
7- Write a MATLAB program to read any integer number (X), then computes and print out the results of
following: A = X ; B=log X; C=ln X; D=eX , E=sine of X; F=cosine of X; G=X7 ; H sin (X) −1 = ; I cos (X) −1 = ; J
tan (X) −1 = ;
X = input('Enter A Number');A = X; B=log10(X); C=log(X); D=exp(X); E=sin(X);
F=cos(X); G=X^7; H= asin(X); I= acos(X);J= atan(X);
disp(A);disp(B);disp(C);disp(D);disp(E);disp(F);disp(G);disp(H);disp(I);
disp(J);
8- Write a MATLAB program to convert the seconds to hours, minutes, and seconds.
s=input('Enter time in seconds:');
S=s; M=s/60; H=s/3600;
disp('Seconds:'); disp(S);
disp('Minutes:'); disp(M);
disp('Hours'); disp(H);
9- Write a MATLAB program to compute the following equations and displaying the output in Cartesian
and Polar form:
% Mohannad Mohamed Mosdak ,9
Z1=3+4j; Z2=7-9j; Z3=5-7j; Z4=2+6j;
A=Z1+Z2/(Z3-Z4); B=Z1*Z2/(Z3+Z4);
MagA=abs(A);ThetaA=angle(A)*180/pi;MagB=abs(B);ThetaB=angle(B)*180/pi;
disp('A in polar form mag and angle:');
A_polar=[MagA, ThetaA]; disp(A_polar);
disp('B in polar form mag and angle:');
B_polar=[MagB, ThetaB]; disp(B_polar);
disp('A in cartesian form:'); disp(A);
disp('B in cartesian form:'); disp(B);
10- Write a MATLAB program (script file) to computes the following equations and display the results in
Cartesian and polar form:
U=X*Y/Z; V=Y*Z/(X*W); where: X=3+j4; Y=5+j8; Z=10; Z =10<60; W = 5<−30;
X=3+4j; Y=5+8j; Z=10*cosd(60)+10*sind(60)*j; W=5*cosd(-30)+5*sind(-30)*j;
U=X*Z/Y; V=Y*Z/(X*W);
disp('U in cartesian form:'); disp(U);
disp('V in cartesian form:'); disp(V);
magU=abs(U); thU=angle(U);
magV=abs(V); thV=angle(V);
U_polar=[magU, thU]; V_polar=[magV, thV];
disp('U in polar form mag and angle:'); disp(U_polar);
disp('V in polar form mag and angle:'); disp(V_polar);
11- Write a MATLAB program to compute the following: V=V1+V2, where: V1 = 70 sin (ωt + 30°) and V2
= 1000 sin (ωt - 60°) and display the results.
V1=70*cosd(30)+70*sind(30)*j; V2=1000*cosd(-60)+1000*sind(-60)*j; V=V1+V2; disp('V in cartesian
form:'); disp(V); magV=abs(V); thV=angle(V); V_polar=[magV, thV]; disp('V in polar form mag and
angle:'); disp('V polar='); disp(V_polar);
12- Write a MATLAB program to asks the user to his name, address, and phone number, and display the
results.
name=input('Enter Your Name:','s');address=input('Enter Your Address:','s');phone=input('Enter Your Phone:','s');
disp('name');disp(name);disp('address');disp(address);disp('phone number');disp(phone);
13- Write a MATLAB program to asks the user to input two vectors, then find the sum of the vectors,
and display the results
V1=input('Enter the first vector:’);V2=input('Enter the second vector:');Sum= V1+V2;
disp('Sum of the two vectors:'); disp(Sum);
14- Write a MATLAB program to asks the user to input two numbers, then compute the addition,
subtraction, multiplication, division, and modulus of the numbers, and display the results
X=input('Enter the fisrt number:'); Y=input('Enter the second number:'); Add=X+Y; Sub=X-Y; Mult=X*Y;
Div=X/Y; Mod=mod(X,Y); disp('Addition of the two numbers:'); disp(Add); disp('Subtraction of the two
numbers:'); disp(Sub); disp('Multiplication of the two numbers:'); disp(Mult); disp('Division of the two
numbers:'); disp(Div); disp('Modulus of the two numbers:'); disp(Mod);
15- Find the results of the following MATLAB program: A=16; X=2/3; Y=7000/3; fprintf('A=%d X=%f
X=%0.2f X=%6.2f X=%0.4f \n', A, X, X, X, X); fprintf('Y=%f Y=%0.2f Y=%0.8f Y=%8.2f \n', Y,Y,Y,Y);
A=16; X=2/3; Y=7000/3;fprintf('A=%d X=%f X=%0.2f X=%6.2f X=%0.4f \n', A, X, X, X, X);fprintf('Y=%f Y=%0.2f
Y=%0.8f Y=%8.2f \n', Y,Y,Y,Y);
Download