Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Assignment

A. Algebra and Arithmetic


This problem requires the symbolic Math Toolbox. The others do not
1. Compute
a. 1111-345 = 346
b. e
14
and 382801 to 15 digits each. Which is bigger?
>> e
14
< 382801
c. the best approximation is 2024/765
2. Compute to 15 digits
a. Cosh(0.1)
>>vpa(cosh(0.1),15)
ans =1.0050041680558
b. ln(2)
>>vpa(log(2),15)
ans =0.693147180559945
c. arctan(1/2)
>>vpa(atan(1/2),15)
ans =0.463647609000806
3. Solve the system of linear equations





>>syms x y z;
>>Ans=solve('3*x+4*y+5*z=2','2*x-3*y+7*z=-1','x-6*y+z=3')
Ans = x: [1x1 sym]
y: [1x1 sym]
z: [1x1 sym]
>> X=Ans.x
X =241/92
>> Y=Ans.y
Y =-21/92
>> Z=Ans.z
Z =-91/92
4. Try to solve the system of linear equations





>>syms x y z;
>>Ans=solve('3*x-9*y+8*z=2','2*x-3*y+7*z=-1','x-6*y+z=3')
Ans= x: [1x1 sym]
y: [1x1 sym]
z: [1x1 sym]
>> X=Ans.x
X =- (13*z1)/3 - 5/3
>> Y=Ans.y
Y =- (5*z1)/9 - 7/9
>> Z=Ans.z
Z =z1
5. Factor the polynomial x
4
y
4

>>syms x y;
>>factor(x^4-y^4)
ans = (x - y)*(x + y)*(x^2 + y^2)
6. Use simplify or simple to simplify the following expressions :
a.
>>A=(1/1+(1/1+(1/x)));
>>simplify(a)
ans =1/x + 2
b.
>> a= cos(x)^2 - sin(x)^2;
>>Simplify(a)
ans = cos(2*x)
7. Compute 3
301
, both as an approximate floating-point number and as an exact integer (
written in usual decimal notation)
>>pretty(sym('3')^301)
ans
:41067443717576512797397808214626494789939108687601230941444057023510699
153249722978140061846706682416475145332179398212844053819829708732369800
3
8. F
9. Use plot and ezplot as appropriation to graph the following functions :
a. y= x
3
x for 4 4
>> x=linspace(-4,4,100);
>> y=(x.^3 - x);
>>plot(x,y)












b. y=

for 2 2
>> x=linspace(-2,2,100);
>> y=sin(1./(x.^2));
>>plot(x,y)
Yes both result are correct!












c. y= tan(x/2) for .
>> y=tan(x/2);
>>plot(x,y)
>>axis([-pi pi -10 10])







d. y =

and y = x
4
x
2
for 2 2
>> x=linspace(-2,2,100);
>> y=exp(-x.^2);
>> z=x.^4 - x.^2;
>>plot(x,y,x,z)












10. Plot the functions x
4
and 2
x
on the same graph and determine how many times their
graphs intersect. Find the approximate values of the points of intersection using fzero
>>ezplot('x.^4');
>> hold on;
>>ezplot('2.^x');
>> hold off
>>title('x^4 and 2^x')


B. Calculus, Graphics, and Linear Algebra
1. Use Contour to do the following :
a. Plot the level curves of the function f(x,y) = 3y + y3 x3
>>syms x y;
>> [x y]=meshgrid(-1:0.1:1);
>> z=3*y + y.^3 - x.^3;
>>contour(x,y,z)













b. Plot the curve 3y + y3 x3 = 5













2. Find the derivatives of the following functions. If possible, simply each answer
a.


>>syms x
>>diff(6*x^3 - 5*x^2 + 2*x - 3)
ans = 18*x^2 - 10*x + 2
b.


>>syms x
>>diff((2*x -1)/(x^2 + 1))
ans =2/(x^2 + 1) - (2*x*(2*x - 1))/(x^2 + 1)^2
c.


>>syms x
>>diff(sin(3*x^2+2))
ans =6*x*cos(3*x^2 + 2)
d.
>>syms x
>>diff(asin(2*x + 3))
ans =2/(1 - (2*x + 3)^2)^(1/2)
e.


>>syms x
>>diff((1+x^4)^(1/2))
ans =(2*x^3)/(x^4 + 1)^(1/2)
f.


>>syms x
>>diff(x^'r')
ans =r*x^(r - 1)
g. aicta


>>syms x
>>diff(atan(x^2 +1))
ans =(2*x)/((x^2 + 1)^2 + 1)
3. See if Matlab can do the following integrals symbolically. For the indefinite integrals, check
the results by differentiating.
a.


>>syms x;
>>int(x*cos(x),0,pi/2)
ans =pi/2 1

b.


>>syms x;
>>int(x*sin(x^2))
ans =-cos(x^2)/2
c. co
>>syms x;
>>int((sin(3*x))*((1-cos(3*x))^(1/2)))
ans =(2*(1 - cos(3*x))^(3/2))/9
d.


>>syms x;
>>int((x^2)*((x+4)^(1/2)))
ans =-(2*(x + 4)^(3/2)*(168*x - 15*(x + 4)^2 + 112))/105
e.


>>syms x;
>>int(exp(-x^2),-inf,inf)
ans =pi^(1/2)
4. Compute the following integrals numerically, using quad8 or quadl :
a.


b.


c.

. In this case, also approximate the error in the numerical answer, by


comparing with the exact answer found in problem 3.
5. Evaluate the following limits :
a.


>>syms x;
>>limit((sin(x)/x),x,0)
ans =1
b.


>>syms x;
>>limit(((1+cos(x)))/(x+pi),x,-pi)
ans =0
c.


>>syms x;
>>limit((x^2)*(exp(-x)),x,inf)
ans =0
d.


>>syms x;
>>limit((1)/(x-1),x,1)
ans =NaN

e.


>>syms x;
>>limit(sin(1/x),x,0,'right')
ans =NaN
6. Compute the following sums :
a.


>>syms k n;
>>symsum(k^2, k, 1, n)
ans =(n*(2*n + 1)*(n + 1))/6
b.


>>syms k n r;
>>symsum(r^k, k, 0, n)
ans =piecewise([r = 1, n + 1], [r <> 1, (r*r^n - 1)/(r - 1)]
c.

You may need the gamma function


_(x)= _(k+1)=k!
>>syms k x;
>>symsum(x^k/gamma(k + 1), k, 0, Inf)
ans =exp(x)
d.


>>syms k z;
>>symsum(1/(z - k)^2, k, -Inf, Inf)
ans =-limit(-psi(k - z, 1), k = -Inf)


7. Find the Taylor polynomial of the indicated order n at the indicated point c for the following
functions :

a.


>>syms x;
>>taylor(exp(x), 7, 0)
ans =x^6/720 + x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1
b.
>>syms x;
>>taylor(sin(x), 5, 0)
ans =x - x^3/6
>>taylor(sin(x), 6, 0)
ans = x^5/120 - x^3/6 + x

c.
>>syms x;
>>taylor(sin(x), 6, 2)
ans =sin(2) - (sin(2)*(x - 2)^2)/2 + (sin(2)*(x - 2)^4)/24 + cos(2)*(x - 2) - (cos(2)*(x -
2)^3)/6 + (cos(2)*(x - 2)^5)/120
d.
>>syms x;
>>taylor(tan(x), 7, 0)
ans =(2*x^5)/15 + x^3/3 + x
e.
>>syms x;
>>taylor(log(x), 5, 1)
ans =x - (x - 1)^2/2 + (x - 1)^3/3 - (x - 1)^4/4 - 1
f. eif
>>syms x;
>>taylor(erf(x), 9, 0)
ans =- x^7/(21*pi^(1/2)) + x^5/(5*pi^(1/2)) - (2*x^3)/(3*pi^(1/2)) + (2*x)/pi^(1/2)
8. Plot the following surfaces :
a. for
>>syms x y;
>> [x,y]=meshgrid([-3*pi:0.2:3*pi],[-3*pi:0.2:3*pi]);
>> z=sin(x)*sin(y);
>>mesh(x,y,z)












b.

co


>>syms x y;
>> [x,y]=meshgrid([-1:0.1:1],[-1:0.1:1]);
>> z=(x.^2 + y.^2)*(cos(x.^2 + y.^2));
>>mesh(x,y,z)






9. In this problem, we use the backslash operator, or left-matrix-divide operator introduced
in the Solving Linear Systems.
a. Use the backslash operator to solve the system of linear equations in Problem 3 of
Practice Set A.
>> A=[3 4 5;2 -3 7;1 -6 1];
>> B=[2;-1;3];
>> X=A\B
>>x=X(1,1)
x =2.619565217391305
>> y=X(2,1)
y =-0.228260869565217
>> z=X(3,1)
z = -0.989130434782609
b. Now try the same method on Problem 4 of Practice Set A. Matlab finds one, but not
all, answer(s). Can you explain why? If not, see Problem 10 below, as well as part (d)
of this problem.
>>syms x y z;
>> A=[3 -9 8;2 -3 7;1 -6 1];
>> B=[2;-1;3];
>> X=A\B;
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 4.189521e-018.
>> x=X(1)
x =-6
>> y=X(2)
y = -1.3333
>> z=X(3)
z =1
c. Next try the method on this problem :
W + 3x 2y + 4z = 1
-2w + 3x +4y z = 1
-4w 3x + y + 2z = 1
2w + 3x 4y + z = 1
Check your answer by matrix multiplication.
>>syms w x y z;
>> A=[1 3 -2 4;-2 3 4 -1;-4 -3 1 2;2 3 -4 1];
>> B=[1;1;1;1];
>> X=A\B;
>> w=X(1)
w =-0.5714
>> x=X(2)
x =0.3333
>> y=X(3)
y =-0.2857
>> z=X(4)
z =0
d. Finally, try the matrix division method on:
ax + by = u
cx + dy = v
Dont forget to declare the variables to be symbolic. Your answer should involve a
fraction, and so will be valid only when its denominator is nonzero. Evaluate deton
the coefficient matrix of the system. Compare with the denominator.

>>syms x y;
>>syms x y a b c d u v;
>> A=[a b;c d];
>> B=[u;v];
>> X=A\B

X =
-(b*v - d*u)/(a*d - b*c)
(a*v - c*u)/(a*d - b*c)

10. We deal in this problem with 3x3 matrices, although the concepts are valid in any
dimension.
a. Consider the rows of a square matrix A . They are vectors in 3-space and so span a
subspace of dimension 3,2,1 or possibly 0 (if all the entries of A are zero). That
number is called the rank of A. The Matlab command rankcomputes the rank of a
matrix. Try it on the four coefficient matrices in each of the parts of Problem 10.
Comment on Matlabs answer for the fourth one.
b. Annxnmatrix is nonsingular if its rank is n. which of the four matrices you computed
in part (a) are nonsingular?
c. Another measure of nonsingularity is given by the determinant a fundamental result
in linear algebra is that a matrix is nonsingular precisely when its determinant is
nonzero. In that case a unique matrix B exists that satisfies AB = BA = the identity
matrix. We denote this inverse matrix by A-1 .Matlab can compute inverses with inv.
Compute det

C. Create Math Script
1. Please created the software for compute the single of linear equations and the system of
linear equations combine together like bellow :

clc;
clearall;
while'Y'
while'Y'
disp('Welcome to the world of Matlab')
disp(' ')
disp('The is the program for compute the single of linear equations and the system of linear
equations')
disp('So, What do you want to do, now?')
disp('1- Compute the Single Equation')
disp('2- Compute the System of Equation')
ch = input('Please choose one of this: ');

ifch == 1
disp('Now you are choose to compute the Single Equation.')
disp('What type of equation you want to compute?')
disp('1- 2nd roots.')
disp('2- 3rd roots.')
disp('3- n roots.')
inp = input('Please choose one of this: ');

ifinp == 1
disp('You had choose to calculate 2nd roots')
disp('ax^2 + bx + C = 0')
a = input('Please Input a: ');
b = input('Please Input b: ');
c = input('Please Input c: ');
teta=b^2-4*a*c;
ifteta<0
x1=(-b-i*sqrt(abs(teta)))/(2*a);
x2=(-b+i*sqrt(abs(teta)))/(2*a);
fprintf('The result is complex : x1=%s and x2=%s\n',num2str(x1),num2str(x2))
elseifteta>=0
x1=(-b-sqrt(teta))/(2*a);
x2=(-b+sqrt(teta))/(2*a);
fprintf('The result of x1 =%f, and x2 =%f.\n',x1,x2)
end
elseifinp == 2
disp('You had choose to calculate 3rd roots')
disp('ax^3 + bx^2 + cx +d = 0')
a = input('Please Input a: ');
b = input('Please Input b: ');
c = input('Please Input c: ');
d = input('Please Input d: ');

A =[a b c d];
X = roots(A);
x1 = X(1);
x2 = X(2);
x3 = X(3);
fprintf('The result of X1 = %f , X2 = %f and X3 = %f\n',x1,x2,x3)

elseifinp == 3
disp('You had choose to calculate n roots')
disp('a1x^n + a2x^n-1 + a3x^n-2+........ +Zx^2 + Sx + Y = 0')
disp('Please Input the number in vector')
disp('Example [a1 a2 a3 a4 a5......a(nth)]')
disp('Example :[1 2 3 4 5 6 7 8 9.........nth]')
P=input('Plese input : ');
X = roots(P)
else
disp('Please check your choosing again or Are you a human?')
end
E = input('Do you want to continue? Yes or No, if Yes please type "Y" but if No please type
"N"?\n','s');
if E == 'Y'
elseif E == 'N'
disp(' ')
disp('This Program is prepared by Mr.Rith')
disp('Thanks a Thousand word for Teacher. Definitely Thanking teacher for teaching us')
disp('Nothing is gonna tear us apart')
disp(':-) :-) :-)')
return
else
disp('Please type your word again or Are you a human?')
disp('Try Again, Press anykey to continue')
pause
end
elseifch == 2
disp('Now you are choose to compute the System of Equation.')
disp('What type of equation you want to compute?')
disp('1- 2nd System.')
disp('2- 3rd System.')
disp('3- n System.')
inp = input('Please choose one of this: ');
ifinp == 1
disp('You had choose to calculate 2nd System of Equation')
disp('|a1x + b1y = c1|')
disp('|a2x + b2y = c2|')
a1 = input('Please Input a1: ');
b1 = input('Please Input b1: ');
c1 = input('Please Input c1: ');
a2 = input('Please Input a2: ');
b2 = input('Please Input b2: ');
c2 = input('Please Input c2: ');
A = [a1 b1;a2 b2];
B = [c1;c2];
X = A\B;
x = X(1);
fprintf('The result of X = %f\n',x)
y = X(2);
fprintf('The result of Y = %f\n',y)
elseifinp == 2
disp('You had choose to calculate 3nd System of Equation')
disp('|a1x + b1y + c1 = d1')
disp('|a2x + b2y + c2 = d2')
disp('|a3x + b3y + c3 = d3')
a1 = input('Please Input a1: ');
b1 = input('Please Input b1: ');
c1 = input('Please Input c1: ');
d1 = input('Please Input d1: ');
a2 = input('Please Input a2: ');
b2 = input('Please Input b2: ');
c2 = input('Please Input c2: ');
d2 = input('Please Input d2: ');
a3 = input('Please Input a3: ');
b3 = input('Please Input b3: ');
c3 = input('Please Input c3: ');
d3 = input('Please Input d3: ');
E = [a1 b1 c1;a2 b2 c2;a3 b3 c3];
D = [d1;d2;d3];
X = E\D;
x = X(1);
fprintf('The result of X = %f\n',x)
y = X(2);
fprintf('The result of Y = %f\n',y)
z = X(3);
fprintf('The result of Z = %f\n',z)
elseifinp == 3
disp('You had choose to calculate n System of Equation')
disp('|a1x + a2y +.......+an(nth)= A|')
disp('|b1x + b2y +......+bn(nth)= B|')
disp('|.......+.......+.......+........=.....|')
disp('|.......+.......+.......+........=.....|')
disp('|N1x + N2x+......+Nn(nth)=N|')
disp('Please input the value as matrix')
disp('Example for the leftside equation : [a1 a2 a3;b1 b2 b3;.....;n1 n2 n3]')
disp('Example : [2 9 0;6 8 4;3 2 0]')
disp('Example for the rightside equation : [A;B;N]')
disp('Example for the rightside equation : [1;6;4]')
E = input('Please input matrix of leftside equation:');
D = input('Please input matrix of rightside equation:');
X = E\D;
disp(X)
else
disp('Please check your choosen again or Are you a human?')
end
else
disp('Please type your choosen again or Are you a human?')
e = input('Do you want to continue? Yes/No?, if Yes please type "Y" but if No please type
"N"?\n','s');
if e == 'Y'
elseif e == 'N'
disp(' ')
disp('This Program is prepared by Mr.Rith')
disp('Thanks a Thousand word for Teacher. Definitely Thanking teacher for teaching us')
disp('Nothing is gonna tear us apart')
disp(':-) :-) :-)')
return
else
disp('Please type your word again or Are you a human?')
disp('Try Again, Press anykey to continue')
pause
end
end
end
end

2. Please write the program that use loop as the first program in the Assignment C, but use for
convert from rectangular to polar and reverse.
clc
clearall;
while'Y'
while'Y'
disp('Welcome to the world of Matlab')
disp(' ')
disp('This Program use for convert from rectangular to polar and polar to rectangular.')
disp('1- Convert from Rectangular to Polar')
disp('2- Convert from Polar to Rectangular')
ch = input('Please choose one of the using above : ');
ifch == 1
disp('1- Convert from Rectangular to Polar')
disp('Convert form : a + jb -> M<theta')
m = input('Please input the value a: ');
n = input('Please input the value b: ');
Com = m + j*n;
M = abs(Com);
theta = angle(Com)*180/pi;
fprintf('The result of M = %f and theta = %f\n',M,theta )
Exit = input('Do you want to continue? Yes or No, if Yes please type "Y" but if No please type
"N"?\n','s');
if Exit == 'Y'
elseif Exit == 'N'

disp('This program is prepared by Mr.Rith')
disp('Thanks a Thousand word to the teacher for teaching us')
disp(':-) :-) :-)')
return
else

disp('you had type the wrong word or Are you a human?')
disp('Please type anykey to continue')
pause
end

elseifch == 2
disp('2- Convert from Polar to Rectangular')
disp('Convert form : M<theta -> a + jb')
M = input('Please input the value of Module: ');
Arg = input('Please input the value of Argument: ');

a = M*cos(Arg * pi/180);
b = M*sin(Arg * pi/180);
A = a + j*b
else
disp('You had put the wrong value or Are you a human?')
disp('Please type your choosing again')
end
exit = input('Do you want to continue? Yes or No, if Yes please type "Y" but if No please type
"N"?\n','s');
if exit == 'Y'
elseif exit == 'N'

disp('This program is prepared by Mr.Rith')
disp('Thanks a Thousand word to the teacher for teaching us')
disp(':-) :-) :-)')
return
else

disp('you had type the wrong word or Are you a human?')
disp('Please type anykey to continue')
pause
end
end
end

3. The preceding script file of problem 1 is tested blow for the following quadratic equations :
a.

+ + = 0
b.
c. og

ta
Recall that while at the command window, the script file is called and executed after that
Using Matlab, let us verify the results obtained in these examples above.

a. 2x^2 + 3x + 7 = 0
Welcome to the world of Matlab
The is the program for compute the single of linear equations and the system of linear
equationsSo, What do you want to do, now?
1- Compute the Single Equation
2- Compute the System of Equation
Please choose one of this: 1
Now you are choose to compute the Single Equation.
What type of equation you want to compute?
1- 2nd roots.
2- 3rd roots.
3- n roots.
Please choose one of this: 1
You had choose to calculate 2nd roots
ax^2 + bx + C = 0
Please Input a: 2
Please Input b: 3
Please Input c: 7
The result is complex : x1=-0.75-1.7139i and x2=-0.75+1.7139i
b. px^2 + 2px + 3p = 0
Welcome to the world of Matlab
The is the program for compute the single of linear equations and the system of linear equations
So, What do you want to do, now?
1- Compute the Single Equation
2- Compute the System of Equation
Please choose one of this: 1
Now you are choose to compute the Single Equation.
What type of equation you want to compute?
1- 2nd roots.
2- 3rd roots.
3- n roots.
Please choose one of this: 1
You had choose to calculate 2nd roots
ax^2 + bx + C = 0
Please Input a: pi
Please Input b: 2*pi
Please Input c: 3*pi
The result is complex : x1=-1-1.4142i and x2=-1+1.4142i

c. log10(32.3)x2 + sqrt (33+1.333.3)x + tan(1.112) = 0
Welcome to the world of Matlab
The is the program for compute the single of linear equations and the system of linear equations
So, What do you want to do, now?
1- Compute the Single Equation
2- Compute the System of Equation
Please choose one of this: 1
Now you are choose to compute the Single Equation.
What type of equation you want to compute?
1- 2nd roots.
2- 3rd roots.
3- n roots.
Please choose one of this: 1
You had choose to calculate 2nd roots
ax^2 + bx + C = 0
Please Input a: log10(32.3)
Please Input b: sqrt(33+1.3333)
Please Input c: tan(1.112)
The result of x1 =-3.499127, and x2 =-0.383362.
4. Consider the electric circuit of Figure.
Please write the program that can change all the value, after that check it to these value
below

10 OHMS
10 OHMS
0.1 H
C1
10uF
clc
clearall;
while'Y'
disp('Welcome to the world of Matlab')
disp('This program is to computed the impedance Zab')
disp(' ')
Res1=input('Please input the value of Resistance R1 : ');
Res2=input('Please input the value of Resestance R2 : ');
Induct=input('Please input the value of Inductance L : ');
Capa=input('Please input the value of Capacitance C : ');
Z= ((Res2+Induct*j)*((Capa/'w')*j))/(Res2+(j*(Induct*'w'+(Capa)/'w')))+Res1;
fprintf('The result is complex : Z=%s\n ',num2str(Z))
exit=input('Do you want to continue? Yes/No?, if Yes please type "Y" but if No please type
"N"?\n','s');
if exit == 'Y'
elseif exit == 'N'
disp('This Program is prepared by Mr.Rith')
disp('Thanks a Thousand word for Teacher. Definitely Thanking teacher for teaching us')
disp('Nothing is gonna tear us apart')
disp(':-) :-) :-)')
return
else
disp('Please type your word again or Are you a human?')
disp('Try Again, Press anykey to continue')
pause
end
end
5. Consider the electric of Figure below, where the radian frequency w (radians/second) of the
applied voltage was varied from 300 to 3000 in steps of radians/second, while the amplitude
was held constant. The ammeter readings were then recorded for each frequency. The
magnitude of the impedance |Z| was computed as |Z| = |V\A| and the data in table below
w(rad/s) |z|ohms w(rad/s) |z| ohms
300
39.339 1700 90.603
400
52.589 1800 81.088
500 71.184 1900 73.588
600 97.665 2000 67.513
700 140.437 2100 62.481
800 222.182 2200 58.240
900 436.056 2300 54.611
1000 1014.938 2400 51.428
1100 469.83 2500 48.717
1200 266.032 2600 46.286
1300 187.052 2700 44.122
1400 145.751 2800 42.182
1500 120.53 2900 40.432
1600 103.111 3000 38.845
R
L
C
+88.8
AC Amps
V1
VSINE
>> w=[300:100:3000];
>>rad=[39.339;52.589;71.184;97.665;140.437;222.182;436.056;1014.938;469.83;266.032;1
87.052;145.751;120.353;103.111;90.603;81.088;73.588;67.513;62.481;58.240;54.611;51.42
8;48.717;46.286;44.122;42.182;40.432;38.845];
>> z=plot(w,rad)

You might also like