engs.education · web viewtaylor: taylor(f, x,a,' o rder',n) returns the taylor series...

14
Taylor: o taylor(f, x,a,'Order',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. o taylor(f, 'Order',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=0. o taylor(f) computes the Taylor series expansion of f up to the fifth order. The expansion point is 0. o taylor(f,Name,Value) uses additional options specified by one or more Name,Value pair arguments. o taylor(f,v) computes the Taylor series expansion of f with respect to v. o taylor(f,v,Name,Value) uses additional options specified by one or more Name,Value pair arguments. o taylor(f,v,a) computes the Taylor series expansion of f with respect to v around the expansion point a. o taylor(f,v,a,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Upload: others

Post on 23-Feb-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Taylor:o taylor(f, x,a,'Order',n) returns the Taylor series expansion of

f(x) of order n-1 at the base point x=a.

o taylor(f, 'Order',n) returns the Taylor series expansion of f(x) of

order n-1 at the base point x=0.

o taylor(f) computes the Taylor series expansion of f up to the

fifth order. The expansion point is 0.

o taylor(f,Name,Value) uses additional options specified by one or

more Name,Value pair arguments.

o taylor(f,v) computes the Taylor series expansion of f with

respect to v.

o taylor(f,v,Name,Value) uses additional options specified by one

or more Name,Value pair arguments.

o taylor(f,v,a) computes the Taylor series expansion of f with

respect to v around the expansion point a.

o taylor(f,v,a,Name,Value) uses additional options specified by

one or more Name,Value pair arguments.

o Note: f must be a symbolic expression representing f(x)

Integration: o int(f)

Definite integrals:

o Integrate from a to b (Area under graph from a to b): int(f,[a b]) or int(f,a,b)

o int(f,x) integrate with respect to x

Differentiation: o Diff(f)o diff(f,n) nth derivative

Page 2: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Partial Differential (multiple variables) :

o diff(f,t) derivative of ‘f’ with respect to t o diff(f,x,n) nth derivative of ‘f’ with respect to x

Substitution:

o subs(diff(g,x), x , n) Evaluate the derivative dg/dx at x = n

Plot f(x) and its Taylor series approximation of degree 3 on the same graph for x in the range [-pi,pi]

syms x;

f = sin(x);

xd = -pi:pi/20:pi; %Specifies x-axis range and scale

yd = subs(f,x,xd); %This evaluates f(x) or y at xd (symbolic).

t3=taylor(f, 'order',4)

td3 = subs(t3,x,xd); %This evaluates t(x) at xd.

plot(xd,yd,’y’);

hold on;

plot(xd,td3,’m’);

o Different approach:

Using inline: inline(expr) constructs an inline function object from the MATLAB® expression contained in expr

Page 3: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

syms x;

f = sin(x);

t3=taylor(f, 'order',4) ; %Taylor series at x=0 of degree 3

f_inline = inline(char(f)); %This changes f from symbolic to function

t3_inline=inline(char(t3)); %This changes t3 from symbolic to function

fplot(f_inline,[-pi ,pi],'b');

hold on;

fplot(t3_inline,[-pi, pi],'r');

legend('exact','Taylor 3');

xlabel('x');

ylabel('function')

Integration using Taylor series range a to b:

syms x;

f=exp(x^2);

t6=taylor(f, 'order',7); %Taylor series at x=0 of degree 6

int(t6,-1,1) %Integration of t6

Integration using Taylor series range a to b using summation method:

o This method depends on writing the MATLAB function f(x) and finding f(1)-f(-1), as follows:

o Open a script file f.m

function s=f(x)

s=0;

for i=0:100

s=s+ x^(2*i+1)/((2*i+1)*factorial(i));

end

Page 4: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

o To run this code, go to command window:>> int_result=f(1)-f(-1)

o Summation method:o Find taylor expansiono Replace x with x2o Find integrationo Add from i=0 to 100

Converting from polar to Cartesiano [x,y] = pol2cart(theta,r)o [theta,r] = cart2pol(x,y) %angle comes first

θ is expressed in radians

polar(theta,r,s): Plots the points defined in polar coordinates as (r,theta) for all values of r and theta. (s is a string that defines the style of the plot)

*pi/180; %Convert to radians *180/pi %Convert to degrees

Plot points (r,theta)

r=[5 5 3 3 3];

theta=[0 60 180 300 -30]*pi/180; %Convert to radians

polar(theta , r, 'x');

Page 5: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Tan inverse:

o atan: Inverse tangent in radians(one input)

o atand: Inverse tangent in degrees(one input)

o atan2: Four-quadrant inverse tangent in radians(two inputs)

o atan2d: Four-quadrant inverse tangent in degrees(two inputs)

o atan2d(Y,X) = atand(Y/X)

linspace(x1,x2): returns a row vector of 100 evenly spaced points

between x1 and x2.

o linspace(x1,x2,n) generates n points. The spacing

between the points is (x2-x1)/(n-1).

linspace is similar to the colon operator, ":",

ones(size(r)):creates a list(or array) of size r eval(expression) evaluates the MATLAB® code represented

by expression

Draw the curve :o r = sin(θ)o theta=linspace(0,2*pi,200); %generates 200 points between 0 and 2πo r=sin(theta);o polar(theta,r,’r’);

Find the area bounded by the curves; Show all curves in one plot:

r = 2 sinθ, θ1 = 45°, θ2 = 135° and the origin

1) plot the 3 curves :

Page 6: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Open script file example7.m

>>theta=linspace(0,2*pi); %or theta=0:2*pi/100:2*pi;

>>r=2*sin(theta);

>>polar(theta,r,’r’); %plots r=2 sin(theta)

>>hold on;

>>r=linspace(0,2);

>>theta=(45*pi/180)*ones(size(r));

>>polar(theta,r,’b’);

>>hold on;

>>r=linspace(0,2);

>>theta=(135*pi/180)*ones(size(r));

>>polar(theta,r,’g’);

2) form the integration and put the limits:

3) Go to command window of MATLAB and do the integration using int:

>>syms theta;

>>area=eval(0.5 * int(4 * sin(theta)^2 , pi/4 , 3*pi/4))

Answer:

area=?

Page 7: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

The quad command is used to numerically evaluate an integral

o Q = quad('f',a,b) approximates the integral of f(x) from a to b

o 'f' is a string containing the name of an m-function to be integrated. Function f must return a vector of output values when given an input vector.

o Q = Inf is returned if an excessive recursion level is reached, indicating a possibly singular integral.

o Typically, a new m-function needs to be created for f when numerically evaluating an integral

o Use inline(expression) to create function

The factor(f) command factors f into polynomial products

The collect command collects coefficients of a symbolic expression and rewrites it as powers of a polynomial:

o collect(s,v)

s is a symbolic expression matrix

v is the independent polynomial variable

Page 8: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

If v is omitted, collect uses rules to determine a default variable

The solve command can be used to solve symbolic expressions with more than one variable:

o solve(f) solves the symbolic expression f using the symbolic variable closest to x as the independent variable

o solve(f, v) solves the symbolic expression f in terms of the independent variable v

roots(p) returns the roots of the polynomial represented by p 

o The roots function solves polynomial equations of the

form p1xn+...+pnx+pn+1=0o For example, p = [3 2 -2] represents the

polynomial 3x2+2x−2.

Page 9: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor
Page 10: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Given the equation

1- Find the solution of the equation assuming that c is the solution variable

2- Find the solution of the equation assuming that b is the solution variable

0242 bcb

Page 11: engs.education · Web viewTaylor: taylor(f, x,a,' O rder',n) returns the Taylor series expansion of f(x) of order n-1 at the base point x=a. taylor(f, ' O rder',n) returns the Taylor

Given the equation of two variables:

x2 + 9y4 = 0

Solve for x in terms of y using Matlab:

» syms x y

» xs=solve(x^2+9*y^4)

xs =

[ 3*i*y^2]

[ -3*i*y^2 ]

24

2 bbc

Roots areComplex Conjugates