Matlab Math.pdf

Post on 13-Dec-2015

263 views 0 download

Tags:

Transcript of Matlab Math.pdf

Matlab Maths Practice

1.Solving AlgebraicEquations and Other Symbolic Tools Solving Basic Algebraic Equations

1.x + 3 = 0

Command window

>> x=solve('x+3=0')

x =

-3

2. x + 8 =0

Command window

>> x=solve('x+8')

x =

-8

3.ax + 5 = 0

>> solve('a*x+5','a')

ans =

-5/x

>> solve('a*x+5','x')

ans =

-5/a

2.Solving Quadratic Equations

x2 6x 12 = 0

Command window

s=solve('x^2-6*x-12=0')

s =

3+21^(1/2)

3-21^(1/2)

3.Plotting Symbolic Equations

1.x^2-6*x-12

command window

d=('x^2-6*x-12');

ezplot(d)

same equation with a example

d='x^2-6*x-12'

command window

>> d='x^2-6*x-12'

d =

x^2-6*x-12

>> ezplot(d,[2,8])

2.we wanted to plot:

x + 3 = 0

4 < x < 4, 2 < y < 2

Command window

>> ezplot('x+3',[-4 4 -2 2])

>>

Output

3.Find the roots of x3 + 3x2 2x 6 and plot the function for �8 < x < 8, �8 < y < 8. Generate the plot with a grid.

command window

>> f='x^3+3*x^2-2*x-6'

f =

x^3+3*x^2-2*x-6

>> s=solve(f)

s =

-3

2^(1/2)

-2^(1/2)

>> ezplot(f,[-8 8,-8,8]),grid on

>>

Graph

4.Systems of Equations

1. 5x + 4y = 3 x - 6y = 2

Command window

>> s=solve('5*x+4*y=3','x-6*y=2');

>> x=s.x

x =

13/17

>> y=s.y

y =

-7/34

2.

w + x + 4y + 3z = 5

2w + 3x + y 2z = 1

w + 2x 5y + 4z = 3

w-3z = 9

command window

>> eq1=('w+x+4*y+3*z=5')

eq1 =

w+x+4*y+3*z=5

>> eq2=('2*w+3*x+y-2*z=1')

eq2 =

2*w+3*x+y-2*z=1

>> eq3=('w+2*x-5*y+4*z=3')

eq3 =

w+2*x-5*y+4*z=3

>> eq4=('w-3*z=9')

eq4 =

w-3*z=9

>> s=solve(eq1,eq2,eq3,eq4)

s =

w: [1x1 sym]

x: [1x1 sym]

y: [1x1 sym]

z: [1x1 sym]

>> w=s.w

w =

1404/127

>> x=s.x

x =

-818/127

>> y=s.y

y =

-53/127

>> z=s.z

z =

87/127

5. Expanding and Collecting Equations

expand

(x + 2) (x 3) = x2 x 6

command window

>> syms x

>> expand((x-1)*(x+4))

ans =

x^2+3*x-4

>> syms y

>> expand(cos(x+y))

ans =

cos(x)*cos(y)-sin(x)*sin(y)

>> expand(sin(x-y))

ans =

sin(x)*cos(y)-cos(x)*sin(y)

>> expand((y-2)*(y+6))

ans =

y^2+4*y-12

>>

collect

>> collect(x*(x^2-2))

ans =

x^3-2*x

>> syms t

>> collect((t+3)*sin(t))

ans =

sin(t)*t+3*sin(t)

Factors

>> factor(x^2-y^2)

ans =

(x-y)*(x+y)

Solving with Exponential and Log Functions

Find a value of x that satisfi es:

log10 (x) log10 (x 3) = 1

command window

>> eq='log10(x)-log10(x-3)=1';

>> s=solve(eq)

s =

10/3

Series Representations of Functions

>> syms x

>> s=taylor(sin(x))

s =

x-1/6*x^3+1/120*x^5

>> ezplot(s)

Computing Derivatives(Important)

>> syms x t

>> f=x^2;

>> g=sin(10+t);

>> diff(f)

ans =

2*x

>> diff(sin(10+t))

ans =

cos(10+t)

To take higher derivatives of a function f, we use the syntax diff(f,n).

>> syms x

>> f=x^4;

>> diff(f,2)

ans =

12*x^2

Show that f (x) x2 satisfies -(df/dx)+2*x=0

>> syms x

>> f=x^2; g=2*x;

>> h=diff(f);

>> -h+g

ans =

0

Does y (t) 3 sin t 7 cos 5t solve y'' y –5 cos 2t?

>> syms t

>> y=3*sin(t)+7*cos(5*t);

>> z=diff(y,2);

>> x=z+y

x =

-168*cos(5*t)

As from the results we can deduce that y(t) cannot solve the above required equation.

Find the minima and maxima of the function f (x) x3 – 3x2 3x in the

interval

[0, 2].

>> syms x

>> f=x^3-3x^2+3*x;

>> f=x^3-3*x^2+3*x;

>> ezplot(f,[0,2])

>> g=diff(f)

g =

3*x^2-6*x+3

>> pretty(g)

2

3 x - 6 x + 3

>> s=solve(g)

s =

1

1

We see that there is only one critical point, since the derivative has a double root.

We can see from the plot that the maximum occurs at the endpoint, but let’s prove

this by evaluating the function at the critical points x 0, 1, 2.

So let’s check f for x 0, 1, 2. We can check all three on a single line and

have MATLAB report the output by passing a comma-delimited list:

Since f (2) returns the largest value, we conclude that the maximum occurs at

x 0. For fun, let’s evaluate the derivative at these three points and plot it:

>> subs(g,0),subs(g,1),subs(g,2)

ans =

3

ans =

0

ans =

3

Where are the critical points of the derivative? We take the second derivative and

set equal to zero:

>> subs(g,0),subs(g,1),subs(g,2)

ans =

3

ans =

0

ans =

3

>> h=diff(g)

h =

6*x-6

>> solve(h)

ans =

1

>> y=diff(h)

y =

6

>>

Plot the function f (x) x4 –2x3 and show any local minima and maxima.

>> syms x

>> f=x^4-2*x^3;

>> ezplot(f,[-2,3]);

>> g=diff(f)

g =

4*x^3-6*x^2

>> s=solve(g)

s =

3/2

0

0

>> h=diff(g)

h =

12*x^2-12*x

>> subs(h,3/2),subs(h,0),subs(h,0)

ans =

9

ans =

0

ans =

0

>>

INTEGRATION

Find int3y sec(x) dy .

command window

>> syms x y

>> int('3*y^2*sec(x)',y)

ans =

y^3*sec(x)

>> a=int('3*y^2*sec(x)',x)

a =

3*y^2*log(sec(x)+tan(x))

>> pretty(a)

2

3 y log(sec(x) + tan(x))

Definite Integration The int command can be used for definite integration by passing the limits over which you want to calculate the integral.

>> int('x',2,3)

ans =

5/2

>> b=int('x^2*cos(x)',-6,6)

b =

68*sin(6)+24*cos(6)

>> double(b)

ans =

4.0438

Matlab Code

>> syms x

>> a=int(exp(-x^2)*sin(x),o,inf)

??? Undefined function or variable 'o'.

>> a=int(exp(-x^2)*sin(x),0,inf)

a =

1/2*pi^(1/2)*erfi(1/2)*exp(-1/4)

>> pretty(a)

1/2

1/2 pi erfi(1/2) exp(-1/4)

>> double(a)

ans =

0.4244

Matlab code

>> syms x

>> int(pi*exp(-2*x),1,2)

ans =

1/2*pi*exp(-2)-1/2*pi*exp(-4)

>> f=1/2*pi*exp(-2)-1/2*pi*exp(-4)

f =

0.1838

Matlab Code

>> syms x y z

>> int(int(int(x*y^2*z^5,x),y),z)

ans =

1/36*x^2*y^3*z^6

Matlab Code

f =

x^2*y

>> int(int(f,x,2,4),y,1,2)

ans =

28

Matlab Code

>> syms r theta z h a

>> v=int(int(int(r,0,h),theta,0,2*pi),z,0,a)

v =

h^2*pi*a

>> subs(v,{a,h},{3.5,5})

ans =

274.8894

>> syms r theta z h a

>> v=int(int(int(r,0,h),theta,0,2*pi),z,0,a)

v =

h^2*pi*a

>> subs(v,{a,h},{3.5,5})

ans =

274.8894

Transforms

Transforms, such as the Laplace, z, and Fourier transforms, are used throughout science and engineering. Besides simplifying the analysis, transforms allow us to see data in a new light. For example, the Fourier transform allows you to view a signal that was represented as a function of time as one that is a function of frequency. In this chapter we will introduce the reader to the basics of using MATLAB to work with transforms. In this chapter we will introduce the laplace, fourier, and fft commands

command window

>> syms a t

>> laplace(a)

ans =

1/s^2

>> laplace(t^2)

ans =

2/s^3

>> laplace(t^7)

ans =

5040/s^8

>> laplace(t^5)

ans =

120/s^6

>> syms w

>> laplace(cos(w*t))

ans =

s/(s^2+w^2)

>> laplace(sin(w*t))

ans =

w/(s^2+w^2)

>> syms b

>> laplace(cosh(b*t))

ans =

s/(s^2-b^2)

>> syms s

>> ilaplace(1/s^3)

ans =

1/2*t^2

>> ilaplace(s/(s^2+4))

ans =

cos(2*t)

>> F=(5-3*s)/(2+5*s)

F =

(5-3*s)/(2+5*s)

>> z=ilaplace(F)

z =

-3/5*dirac(t)+31/25*exp(-2/5*t)

>> pretty(z)

31

- 3/5 dirac(t) + -- exp(- 2/5 t)

25

Matlab code

>> syms s

>> f=ilaplace(1/(s+7)^2)

f =

t*exp(-7*t)

>> pretty(f)

t exp(-7 t)

>> ezplot(f,[0,5])

>> syms s

>> f=((2*s)+3)/((s+1)^2*(s+3)^2)

f =

(2*s+3)/(s+1)^2/(s+3)^2

>> pretty(f)

2 s + 3

-----------------

2 2

(s + 1) (s + 3)

>> ilaplace(f)

ans =

1/4*exp(-t)*(1+t)-1/4*exp(-3*t)*(1+3*t)

>> ezplot(f,[0,7])

Math Book solve Problems

John and birds

Calculus

Integration

>> syms x

>> int 3*X^4

ans =

3/5*X^5

>> int (2/x^2,x)

ans =

-2/x

>> c=int(sqrt(x))

c =

2/3*x^(3/2)

>> pretty(c)

3/2

2/3 x

>> d=int(3*x+2*x^2-5,x)

d =

3/2*x^2+2/3*x^3-5*x

>> pretty(d)

2 3

3/2 x + 2/3 x - 5 x

>> int(4+(3/7*x)-6*x^2,x)

ans =

4*x+3/14*x^2-2*x^3

>> a=((2*x^3)/(4*x)-(3*x)/(4*x))

a =

1/2*x^2-3/4

>> pretty(a)

2

1/2 x - 3/4

>> int(a)

ans =

1/6*x^3-3/4*x

Matlab code

>> syms t

>> a=int(1-t^2,t)

a =

t-1/3*t^3

>> pretty(a)

3

t - 1/3 t

Matlab code

>> syms t

>> a=(-5/9)*(t^-0.75)

a =

-5/9/t^(3/4)

pretty(a)

111 1

- --- ----

200 3/4

t

>> a=(-5/9)*(t^-0.75)

a =

-5/9/t^(3/4)

>> int(a)

ans =

-20/9*t^(1/4)

>> b=int(a)

b =

-20/9*t^(1/4)

>> pretty(b)

1/4

- 20/9 t

Matlab code

>> syms m

>> a=(2*m^2+1)/m

a =

(2*m^2+1)/m

>> pretty(a)

2

2 m + 1

--------

m

>> b=int(a,m)

b =

m^2+log(m)

>> pretty(b)

2

m + log(m)

>> a=(3*sin(2*x))

a =

3*sin(2*x)

>> pretty(a)

3 sin(2 x)

>> b=int(a,0,pi/2)

b =

3

Matlab code

>> syms t

>> a=4*cos(3*t)

a =

4*cos(3*t)

>> pretty(a)

4 cos(3 t)

>> b=int(a,1,2)

b =

-4/3*sin(3)+4/3*sin(6)

>> pretty(b)

- 4/3 sin(3) + 4/3 sin(6)

>> double(b)

ans =

-0.5607

Matlab code

>> syms x

>> a=3*(sec(2*x))^2

a =

3*sec(2*x)^2

>> pretty (a)

2

3 sec(2 x)

>> int(a,0,pi/6)

ans =

3/2*3^(1/2)

>> b=int(a,0,pi/6)

b =

3/2*3^(1/2)

>> pretty(b)

1/2

3/2 3

>> double(b)

ans =

2.598

Matlab code

>> syms x

>> ezplot(x^3-2*x^2-8*x)

>> %From Graph limits are -2 to 0 and from 0 to 4

>> syms y

>> int(x^3-2*x^2-8*x,-2,0)-int(x^3-2*x^2-8*x,0,4)

ans =

148/3

Matlab Code

Limits are find by plotting both functions

>> syms x

>> int(7-x,-3,2)-int(x^2+1,-3,2)

ans =

125/6

>> f=int(7-x,-3,2)-int(x^2+1,-3,2)

f =

125/6

>> double(f)

ans =

20.8333

Matlab Code

>> x=linspace(-5,5,20);

>> y1=x.^2+3;

>> y2=7-3*x;

>> plot(x,y1,'ko',x,y2,'r*')

>> plot(x,y1,'k',x,y2,'r'

>> plot(x,y1,'k',x,y2,'r')

limits are -4 and 1

>> clear x

>> syms x

>> int(7-3*x,-4,1)-int(x.^2+3,-4,1)

ans =

125/6

Matlab Code

> syms x

>> f=(x^2+4)^2

f =

(x^2+4)^2

>> f1=expand(f)

f1 =

x^4+8*x^2+16

>> f2=(pi*f1)

f2 =

pi*(x^4+8*x^2+16)

>> f3=int(f2,1,4)

f3 =

2103/5*pi

>> double(f3)

ans =

1.3214e+003

Matlab code

>> syms t

>> f=2*(cos(4*t))^2

f =

2*cos(4*t)^2

>> pretty(f)

2

2 cos(4 t)

>> int(f,0,pi/4)

ans =

1/4*pi

Matlab code

>> syms t

> f=(sin(t))^2*(cos(t))^4

f =

sin(t)^2*cos(t)^4

>> pretty(f)

2 4

sin(t) cos(t)

>> int(f)

ans =

-1/6*sin(t)*cos(t)^5+1/24*cos(t)^3*sin(t)+1/16*cos(t)*sin(t)+1/16*t

>> f1=int(f)

f1 =

-1/6*sin(t)*cos(t)^5+1/24*cos(t)^3*sin(t)+1/16*cos(t)*sin(t)+1/16*t

>> pretty(f1)

5 3

- 1/6 sin(t) cos(t) + 1/24 cos(t) sin(t) + 1/16 cos(t) sin(t) + 1/16 t

Matlab code

> syms a x

>> f=1/(a^2-x^2)

f =

1/(a^2-x^2)

>> pretty(f)

1

-------

2 2

a - x

>> f=1/sqrt(a^2-x^2)

f =

1/(a^2-x^2)^(1/2)

>> pretty(f)

1

------------

2 2 1/2

(a - x )

>> f1=int(f)

f1 =

atan(x/(a^2-x^2)^(1/2))

>> pretty(f1)

x

atan(------------)

2 2 1/2

(a - x )

Matlab Code

>> syms x

>> f=1/sqrt(x^2+4)

f =

1/(x^2+4)^(1/2)

> pretty(f)

1

-----------

2 1/2

(x + 4)

>> f1=int(f,0,2)

f1 =

-log(2^(1/2)-1)

>> pretty(f1)

1/2

-log(2 - 1)

>> f2=double(f1)

f2 =

0.8814

Matlab Code

>> syms x

>> f=(3*x^2+16*x+15)/(x+3)^3

f =

(3*x^2+16*x+15)/(x+3)^3

>> pretty(f)

2

3 x + 16 x + 15

----------------

3

(x + 3)

>> f1=int(f,-2,1)

f1 =

-69/16+6*log(2)

>> pretty(f1)

69

- -- + 6 log(2)

16

>> f2=double(f1)

f2 =

-0.1536

Matlab Code

>> syms x

>> f=3*x^2*exp(x/2)

f =

3*x^2*exp(1/2*x)

>> pretty(f)

2

3 x exp(1/2 x)

>> f1=int(f,1,2)

f1 =

-30*exp(1/2)+24*exp(1)

>> pretty(f1)

-30 exp(1/2) + 24 exp(1)

>> f2=double(f1)

f2 =

15.7771

Matlab Code

> syms t

>> f=4*t^3*cos(t)

f =

4*t^3*cos(t)

> pretty(f)

3

4 t cos(t)

>> int(f,1,2)

ans =

20*sin(1)+12*cos(1)-16*sin(2)+24*cos(2)

>> f1=int(f,1,2)

f1 =

20*sin(1)+12*cos(1)-16*sin(2)+24*cos(2)

>> pretty(f1)

20 sin(1) + 12 cos(1) - 16 sin(2) + 24 cos(2)

>> f2=double(f1)

f2 =

-1.2232

Matlab Code

>> syms t

>> f=(sin(t))^2*(cos(t))^6

f =

sin(t)^2*cos(t)^6

>> pretty(f)

2 6

sin(t) cos(t)

>> f1=int(f,0,pi/2)

f1 =

5/256*pi

>> pretty(f1)

5/256 pi

>> f2=double(f1)

f2 =

0.0614

Matlab Code

>> syms x

>> y=12*x^3;

>> y1=diff(y,x)

y1 =

36*x^2

>> pretty(y1)

2

36 x

Matlab code

>> syms x

>> y=3*sin(4*x)

y =

3*sin(4*x)

>> pretty(y)

3 sin(4 x)

>> y1=diff(y)

y1 =

12*cos(4*x)

>> pretty(y1)

12 cos(4 x)

Matlab code

>> syms x

>> y=3*x^2*sin(2*x)

y =

3*x^2*sin(2*x)

>> pretty(y)

2

3 x sin(2 x)

>> y1=diff(y)

y1 =

6*x*sin(2*x)+6*x^2*cos(2*x)

>> pretty(y1)

2

6 x sin(2 x) + 6 x cos(2 x)

Matlab code

>> syms t

>> y=(t*exp(2*t)/2*cos(t))

y =

1/2*t*exp(2*t)*cos(t)

>> pretty(y)

1/2 t exp(2 t) cos(t)

>> y1=diff(y)

y1 =

1/2*exp(2*t)*cos(t)+t*exp(2*t)*cos(t)-1/2*t*exp(2*t)*sin(t)

>> pretty(y1)

1/2 exp(2 t) cos(t) + t exp(2 t) cos(t) - 1/2 t exp(2 t) sin(t)

>>

Matlab Code

>> syms x

>> y=3*(tan(3*x))^4

y =

3*tan(3*x)^4

>> y1=diff(y)

y1 =

12*tan(3*x)^3*(3+3*tan(3*x)^2)

>> pretty(y1)

3 2

12 tan(3 x) (3 + 3 tan(3 x) )

>> 12*tan(3*x)^3*(3+3*tan(3*x)^2)

pretty(y1)

3 2

12 tan(3 x) (3 + 3 tan(3 x) )

Matlab code

>> syms x

>> y=2*x*exp(-3*x)

y =

2*x*exp(-3*x)

>> pretty(y)

2 x exp(-3 x)

>> y1=diff(y)

y1 =

2*exp(-3*x)-6*x*exp(-3*x)

>> pretty(y1)

2 exp(-3 x) - 6 x exp(-3 x)

>> y2=diff(y1)

y2 =

-12*exp(-3*x)+18*x*exp(-3*x)

>> pretty(y2)

-12 exp(-3 x) + 18 x exp(-3 x)

>> y3=y2+6*y1+9*y

y3 =

0

Matlab Code

>> dsolve('Dy=y*t/(t-5)','y(0)=2')

ans =

-2/3125*exp(t)*t^5+2/125*exp(t)*t^4-4/25*exp(t)*t^3+4/5*exp(t)*t^2-2*exp(t)*t+2*exp(t)

Matlab Code

>> s=dsolve('Dy=t+3','y(0)=7')

s =

1/2*t^2+3*t+7

Matlab Code

>> dsolve('D2y-y=0','y(0)=-1','Dy(0)=2')

ans =

-3/2*exp(-t)+1/2*exp(t)

JOHN BIRDS MATHEMATICS PROBLEMS WITH MATLAB

Matlab Code

>> syms a b c

>> y=(a^3*b^2*c^4)/(a*b*c^-2)

y =

a^2*b*c^6

>> pretty(y)

2 6

a b c

>> subs(y,[a,b,c],[3,1/8,2])

ans =

72

Matlab Code

>> syms x y

>> z=((x^2*y^3+x*y^2)/(x*y))

z =

(x^2*y^3+x*y^2)/x/y

>> pretty(z)

2 3 2

x y + x y

------------

x y

>> simplify(z)

ans =

y*(x*y+1)

Matlab Code

> z=((x^2*sqrt(y))*(sqrt(x)*(y^2)^1.5))/((x^5*y^3)^0.5)

z =

x^(5/2)*y^(1/2)*(y^2)^(3/2)/(x^5*y^3)^(1/2)

>> pretty(z)

5/2 1/2 2 3/2

x y (y )

-----------------

5 3 1/2

(x y )

>> simplify(z)

ans =

x^(5/2)*y^(7/2)*csgn(y)/(x^5*y^3)^(1/2)

Matlab Code

>> expand((3*x+2*y)*(x-y))

ans =

3*x^2-x*y-2*y^2

Matlab Code

>> syms a b c

>> expand((2*a-3)/(4*a )+5*6-3*a)

ans =

61/2-3/4/a-3*a

Matlab Code

>> solve('(sqrt(t)+3)/(sqrt(t))=2')

ans =

9

Matlab Code

>> syms x

>> solve('4-3*x=2*x-11')

ans =

3

Matlab Code

>> syms x

>> solve('3/(x-2)=4/(3*x+4)')

ans =

-4

Matlab Code

>> solve('3*x-2-5*x=2*x-4')

ans =

1/2

Matlab Code

>> solve('8+4*(x-1)-5*(x-3)=2*(5-2*x)')

ans =

-3

Matlab Code

>> syms a

>> solve('(1/(3*a-2))+(1/(5*a+3))')

ans =

-1/8

Matlab Code

>> syms t

>> solve('((3*sqrt(t))/(1-sqrt(t))=-6)')

ans =

4

Matlab Code

>> syms x y

s=solve('8*x-3*y=51','3*x+4*y=14');

>> x=s.x

x =

6

>> y=s.y

y =

-1

Matlab Code

>> s=solve('5*a=1-3*b','2*b+a+4=0');

>> a=s.a

a =

2

>> b=s.b

b =

-3

Matlab Code

>> syms x y

>> s=solve('x/5+2*y/3=49/15','3*x/7-y/2+5/7=0');

>> x=s.x

x =

3

>> y=s.y

y =

4

Matlab Code

>> solve('x^2+4*x-32=0')

ans =

4

-8

2nd Code

>> a=[1 4 -32]

a =

1 4 -32

>> roots(a)

ans =

-8

4

Matlab Code

>> solve('8*x^2+2*x-15=0')

ans =

5/4

-3/2

>> a=[8 2 -15]

2nd Code

a =

8 2 -15

>> roots(a)

ans =

-1.5000

1.2500

Matlab Code

>> a=[2 -5]

a =

2 -5

>> a=poly(a)

a =

1 3 -10

RESOLVE THE FRACTION

f (x) =3x3 - 2x2 + 4x - 3

x2 + 3x + 3

Matlab Code

>> b=[3 -2 4 -3]

b =

3 -2 4 -3

>> a=[1 3 3]

a =

1 3 3

>> [q r]=deconv(b,a)

q =

3 -11

r =

0 0 28 30

matlab code means

f (x) = (3x -11) +28x + 30

x2 + 3x + 3

Partial Fraction Expansion

The command RESIDUE can be used to perform partial fraction expansion directly (RESIDUE

itself makes use of both ROOTS and DECONV behind the scenes). You provide two input

vectors, which again represent the numerator and denominator polynomials, just like the

DECONV command. MATLAB returns three outputs: the first is a vector of residues, the

second a vector of poles, and the third a vector of coefficients for any remainder polynomial that

exists.

F(s) =B(s)

A(s)=

3s+1

s3 + 3s2 + 2s

Matlab Code

>> b=[3 1]

b =

3 1

>> a=[1 3 2 0]

a =

1 3 2 0

>> [r p k]=residue(b,a)

r =

-2.5000

2.0000

0.5000

p =

-2

-1

0

k =

[]

answer is

F(s) =-2.5

s+ 2+

2

s+1+

0.5

s

Matlab Code

>> b=[-3 11]

b =

-3 11

>> a=[1 2 -3]

a =

1 2 -3

>> [r p k]=residue(b,a)

r =

-5

2

p =

-3.0000

1.0000

k =

[]

Matlab Code

>> collect((x+1)*(x-2)*(x+3))

ans =

-6+x^3+2*x^2-5*x

>> b=[2 -9 -35]

b =

2 -9 -35

>> a=[1 2 -5 -6]

a =

1 2 -5 -6

>> [r p k]=residue(b,a)

r =

1.0000

-3.0000

4.0000

p =

-3.0000

2.0000

-1.0000

k =

[]

Matlab Code

> b=[1 0 1]

b =

1 0 1

>> a=[1 -3 2]

a =

1 -3 2

>> [r p k]=residue(b,a)

r =

5

-2

p =

2

1

k =

1

Matlab Code

>> b=[1 -2 -4 -4]

b =

1 -2 -4 -4

>> a=[1 1 -2]

a =

1 1 -2

>> [r p k]=residue(b,a)

r =

4

-3

p =

-2

1

k =

1 -3

Matlab Code

>> b=[2 3]

b =

2 3

>> a=[1 -4 4 ]

a =

1 -4 4

>> [r p k]=residue(b,a)

r =

2

7

p =

2

2

k =

[]

Matlab Code

>> syms x

>> q=(x+3)*(x-1)^2

q =

(x+3)*(x-1)^2

>> expand(q)

ans =

x^3+x^2-5*x+3

>> b=[5 -2 -19]

b =

5 -2 -19

>> a=[1 1 -5 3]

a =

1 1 -5 3

>> [r p k]=residue(b,a)

r =

2.0000

3.0000

-4.0000

p =

-3.0000

1.0000

1.0000

k =

[]

Matlab Code

>> syms x

>> q=(x+3)^3

q =

(x+3)^3

>> q=expand(q)

q =

x^3+9*x^2+27*x+27

>> b=[3 16 15]

b =

3 16 15

>> a=[1 9 27 27]

a =

1 9 27 27

>> [r p k]=residue(b,a)

r =

3.0000

-2.0000

-6.0000

p =

-3.0000

-3.0000

-3.0000

k =

[]

Matlab Code

>> syms x

>> b=[12]

b =

12

>> a=[1 0 -9]

a =

1 0 -9

>> [r p k]=residue(b,a)

r =

2

-2

p =

3

-3

k =

[]

Matlab Code

>> syms x

>> b=[4 -4]

b =

4 -4

>> a=[1 -2 -3]

a =

1 -2 -3

>> [r p k]=residue(b,a)

r =

2.0000

2.0000

p =

3.0000

-1.0000

k =

[]

Matlab Code

>> syms x

>> q=x*(x-2)*(x-1)

q =

x*(x-2)*(x-1)

>> expand(q)

ans =

x^3-3*x^2+2*x

>> b=[1 -3 6]

b =

1 -3 6

>> a=[1 3 2 0]

a =

1 3 2 0

>> a=[1 -3 2 0]

a =

1 -3 2 0

>> [r p k]=residue(b,a)

r =

2

-4

3

p =

2

1

0

k =

[]

Matlab Code

>> syms x y z

>> s=solve('x+y+z=4','2*x-3*y+4*z=33','3*x-2*y-2*z=2');

>> x=s.x

x =

2

>> y=s.y

y =

-3

>> z=s.z

z =

5

Matlab Code

>> syms p q r

>> s=solve('p+2*q+3*r=-7.8','2*p+5*q-r=1.4','5*p-q+7*r=3.5');

>> p=s.p

p =

4.1000000000000000000000000000000

>> q=s.q

q =

-1.9000000000000000000000000000000

>> r=s.r

r =

-2.7000000000000000000000000000000

Matlab Code

>> syms x

>> y=x^2

y =

x^2

>> pretty(y)

2

x

>> diff(y)

ans =

2*x

>> subs(ans,2)

ans =

4

Matlab Code

>> syms x

>> y=5*x^4+4*x-1/(2*x^2)+1/sqrt(x)-3

y =

5*x^4+4*x-1/2/x^2+1/x^(1/2)-3

>> pretty(y)

4 1 1

5 x + 4 x - 1/2 ---- + ---- - 3

2 1/2

x x

>> a=diff(y)

a =

20*x^3+4+1/x^3-1/2/x^(3/2)

>> pretty(a)

3 1 1

20 x + 4 + ---- - 1/2 ----

3 3/2

x x

Matlab Code

>> syms x

>> y=3*x^4-2*x^2+5*x-2

y =

3*x^4-2*x^2+5*x-2

>> pretty(y)

4 2

3 x - 2 x + 5 x - 2

>> a=diff(y)

a =

12*x^3-4*x+5

>> subs(a,0)

ans =

5

>> subs(a,1)

ans =

13

Matlab Code

>> syms x

>> y=3*x^2*sin(2*x)

y =

3*x^2*sin(2*x)

>> pretty(y)

2

3 x sin(2 x)

>> a=diff(y)

a =

6*x*sin(2*x)+6*x^2*cos(2*x)

>> pretty(a)

2

6 x sin(2 x) + 6 x cos(2 x)

Matlab Code

>> syms t

>> v=5*t*sin(2*t)

v =

5*t*sin(2*t)

>> pretty(v)

5 t sin(2 t)

>> a=diff(v)

a =

5*sin(2*t)+10*t*cos(2*t)

>> pretty(a)

5 sin(2 t) + 10 t cos(2 t)

>> subs(a,0.20)

ans =

3.7892

Matlab Code

>> syms t

>> y=exp(t)*sin(4*t)

y =

exp(t)*sin(4*t)

>> syms t

>> y=exp(t)*sin(4*t)

y =

exp(t)*sin(4*t)

Matlab Code

>> syms t

>> z=2*exp(3*t)*sin(2*t)

z =

2*exp(3*t)*sin(2*t)

>> pretty(z)

2 exp(3 t) sin(2 t)

>> a=diff(z)

a =

6*exp(3*t)*sin(2*t)+4*exp(3*t)*cos(2*t)

>> pretty(a)

6 exp(3 t) sin(2 t) + 4 exp(3 t) cos(2 t)

>> subs(a,0.5)

ans =

32.3131

Matlab Code

>> syms t

>> y=t*exp(2*t)/2*cos(t)

y =

1/2*t*exp(2*t)*cos(t)

>> pretty(y)

1/2 t exp(2 t) cos(t)

>> a=diff(y)

a =

1/2*exp(2*t)*cos(t)+t*exp(2*t)*cos(t)-1/2*t*exp(2*t)*sin(t)

>> pretty(a)

1/2 exp(2 t) cos(t) + t exp(2 t) cos(t) - 1/2 t exp(2 t) sin(t)

Matlab Code

>> syms x

>> y=sqrt(3*x^2+4*x-1)

y =

(3*x^2+4*x-1)^(1/2)

>> pretty(y)

2 1/2

(3 x + 4 x - 1)

>> a=diff(y)

a =

1/2/(3*x^2+4*x-1)^(1/2)*(6*x+4)

>> pretty(a)

6 x + 4

1/2 -------------------

2 1/2

(3 x + 4 x - 1)

Matlab Code

>> syms t

>> y=2*exp(-0.9*t)*sin(2*pi*5*t)

y =

2*exp(-9/10*t)*sin(10*pi*t)

>> a=diff(y)

a =

-9/5*exp(-9/10*t)*sin(10*pi*t)+20*exp(-9/10*t)*cos(10*pi*t)*pi

>> subs(a,1)

ans =

25.5455

Matlab Code