
s02A
%problem 1
3+9

ans =

    12

2^123

ans =

     1.063382396627933e+37

vpa('pi^2',35)
 
ans =
 
9.8696044010893586188344909998761512
 
     vpa('exp(1)',35)
 
ans =
 
2.7182818284590452353602874713526625
 
a=22/7

a =

   3.14285714285714

b=311/99

b =

   3.14141414141414

c=355/113

c =

   3.14159292035398

pi-a

ans =

  -0.00126448926735

pi-b

ans =

     1.785121756516794e-04

pi-c

ans =

    -2.667641894049666e-07

% c is the best approximation to pi.
%problem 2
sin(0.1)/0.1

ans =

   0.99833416646828

sin(.01)/.01

ans =

   0.99998333341667

sin(.001)/.001

ans =

   0.99999983333334


%problem 3
syms x y
factor(x^3-y^3)
 
ans =
 
(x-y)*(x^2+x*y+y^2)
 
     factor(sym('123456789'))
 
ans =
 
(3)^2*(3803)*(3607)
 

%problem 4
x=linspace(-5,5,201);y=3*x+2;
plot(x,y)
     title('graph for 4a')
pause
y=x.^2+x-1;
plot(x,y)
     title('graph for 4b')
pause
clear x y
x=linspace(0,4*pi,401); y=sin(x); plot(x,y)
     title('graph for 4c')
pause
clear x y
x=linspace(-pi/2,pi/2,201); y=tan(x); plot(x,y)
     title('graph for 4d')
pause
     clear x y
x=linspace(-2,2,201);y=exp(-x.^2); plot(x,y)
title('graph for 4e')
pause
s02Ab
echo on
x=linspace(-1,0,101);y=x.^4;plot(x,y)
hold on
y=2.^x; plot(x,y)
     title('graphs of y=x^4 and y=2^x')
pause
f=inline('x.^4-2.^x')

f =

     Inline function:
     f(x) = x.^4-2.^x

     z=fzero(f,-.5)

z =

  -0.86134533230965

     f(z)

ans =

     2.220446049250313e-16

     w=solve('x^4=2^x')
 
w =
 
[   -4*lambertw(-1/4*log(2))/log(2)]
[                                16]
[ -4*lambertw(-1/4*i*log(2))/log(2)]
[    -4*lambertw(1/4*log(2))/log(2)]
[  -4*lambertw(1/4*i*log(2))/log(2)]
 
     a=double(w)

a =

  1.23962772952276                    
 16.00000000000000                    
 -0.16088749573030 + 0.95910474628018i
 -0.86134533230965                    
 -0.16088749573030 - 0.95910474628018i

% note 3 real roots were found
x=linspace(1,2,101);y=x.^4;plot(x,y)
hold on
y=2.^x; plot(x,y)
     title('graphs of y=x^4 and y=2^x')
pause
     z=fzero(f,2)

z =

   1.23962772952276

     f(z)

ans =

    -8.881784197001252e-16

x=linspace(10,20,201);y=x.^4;plot(x,y)
hold on
y=2.^x; plot(x,y)
     title('graphs of y=x^4 and y=2^x')
pause
     z=fzero(f,15)

z =

    16

     f(z)

ans =

     0

s02Ac
echo on
% problem 6a
[X Y]=meshgrid(-1:0.1:1,-1:0.1:1);
contour(X,Y,3*Y+Y.^3-X.^3)
     title ('level curves of 3y+y^3-x^3')
pause
[X Y]=meshgrid(-10:0.1:10,-10:0.1:10);
contour(X,Y,3*Y+Y.^3-X.^3)
     title ('level curves of 3y+y^3-x^3')
pause
% problem 6b
contour(X,Y,3*Y+Y.^3-X.^3,[5 5])
     title ('graph of 3y+y^3-x^3=5')
pause
%problem 6c
contour(X,Y, Y.*log(X)+X.*log(Y), [0 0])
Warning: Log of zero.
> In /home1/pnw/s02Ac.m at line 16
Warning: Log of zero.
> In /home1/pnw/s02Ac.m at line 16
     title('graph 0f yln(x)+xln(y)=0')
pause
s02Ad
echo on 

% problem 7
syms x a

diff(7*x^3+3*x^2-2*x-1,x)
 
ans =
 
21*x^2+6*x-2
 

     diff((x+1)/(x^2+1),x)
 
ans =
 
1/(x^2+1)-2*(x+1)/(x^2+1)^2*x
 
     simplify(ans)
 
ans =
 
-(x^2-1+2*x)/(x^2+1)^2
 

	  diff(cos(x^2+1),x)
 
ans =
 
-2*sin(x^2+1)*x
 
     diff(asin(2*x+3),x)
 
ans =
 
1/(-2-x^2-3*x)^(1/2)
 

     diff(sqrt(1+x^4),x)
 
ans =
 
2/(1+x^4)^(1/2)*x^3
 

     diff(a^x,x)
 
ans =
 
a^x*log(a)
 

     diff(atan(x),x)
 
ans =
 
1/(x^2+1)
 

%  problem 8
factor(x^6-21*x^5+175*x^4-735*x^3+1624*x^2-1764*x+720)
 
ans =
 
(x-1)*(x-2)*(x-3)*(x-4)*(x-5)*(x-6)
 
     solve('x^6-21*x^5+175*x^4-735*x^3+1624*x^2-1764*x+720=0')
 
ans =
 
[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[ 6]
 

     t=linspace(0.5,6.5,1001);s=t.^6-21*t.^5+175*t.^4-735*t.^3+1624*t.^2;
     s=s-1764*t+720; plot(t,s)
pause
diff(x^6-21*x^5+175*x^4-735*x^3+1624*x^2-1764*x+720)
 
ans =
 
6*x^5-105*x^4+700*x^3-2205*x^2+3248*x-1764
 
     u=6*t.^5-105*t.^4+700*t.^3-2205*t.^2+3248*t-1764;
     plot(t,s,t,u)
     title('graph of p and pprime ')
% p is increasing where p' is positve, decreasing where p' is negative.
pause

%problem 9
     limit(sin(x)/x)
 
ans =
 
1
 

     limit((1+cos(x))/(x-pi),x,pi)
 
ans =
 
0
 

     limit(x*exp(-x),x,inf)
 
ans =
 
0
 

     limit(1/(1-x),x,1,'left')
 
ans =
 
inf
 

     limit(sin(1/x))
 
ans =
 
-1 .. 1
 
s02Ae
echo on
% problem 10
syms x

int('sin(x)',x,0,pi/2)
 
ans =
 
1
 

     int('x*cos(x^2)',x)
 
ans =
 
1/2*sin(x^2)
 

     int('sin(3*x)*sqrt(1-cos(3*x))',x)
 
ans =
 
2/9*(1-cos(3*x))^(3/2)
 

     int('log(x)',x)
 
ans =
 
x*log(x)-x
 

     int('x^2*sqrt(x+4)',x)
 
ans =
 
2/7*(x+4)^(7/2)-16/5*(x+4)^(5/2)+32/3*(x+4)^(3/2)
 

     int('sqrt(x^4+1)',x)
 
ans =
 
1/3*x*(x^4+1)^(1/2)+2/3/(1/2*2^(1/2)+1/2*i*2^(1/2))*(1-i*x^2)^(1/2)*(1+i*x^2)^(1/2)/(x^4+1)^(1/2)*EllipticF(x*(1/2*2^(1/2)+1/2*i*2^(1/2)),i)
 

     int('exp(cos(x))',x)
Warning: Explicit integral could not be found.
> In /usr/local/matlab6.1/toolbox/symbolic/@sym/int.m at line 58
  In /home1/pnw/s02Ae.m at line 18
 
ans =
 
int(exp(cos(x)),x)
 

     int('exp(-x^2)',x,-inf,inf)
 
ans =
 
pi^(1/2)
 

% problem 11
Q=quadl('exp(cos(x))',0,pi)

Q =

   3.97746326050299


     Q=quadl('sqrt(x.^4+1)',0,1)

Q =

   1.08942935729903

