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.
14
Embed
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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
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
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
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');
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: