1、Taylor Series in MATLABThe statementssyms xf = 1/(5+4*cos(x)T = taylor(f,8)return T =1/9+2/81*x2+5/1458*x4+49/131220*x6which is all the terms up to, but not including, order eight in the Taylor series for f(x):Technically, T is a Maclaurin series, since its basepoint is a = 0. The commandpretty(T)pr
2、ints T in a format resembling typeset mathematics: 2 4 49 61/9 + 2/81 x + 5/1458 x + - x 131220These commands syms xg = exp(x*sin(x)t = taylor(g,12,2);generate the first 12 nonzero terms of the Taylor series for g about x = 2. Next, plot these functions together to see how well this Taylor approxima
3、tion compares to the actual function g: xd = 1:0.05:3; yd = subs(g,x,xd);ezplot(t, 1,3); hold on;plot(xd, yd, r-.)title(Taylor approximation vs. actual function);legend(Taylor,Function)1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3123456xTaylor aproximation vs. actual functionTaylorFunctionplot Plot the real
4、-world values of two fi objects against each otherSyntaxplot(a)plot(a,b)plot(a,b,s)plot(a1,b1,s1,a2,b2,s2,.)DescriptionThe plot function for fi objects works the same as the built-in plot function. plot(a) plots the columns of a versus their index. If a is complex, plot(a) is equivalent to plot(real
5、(a),imag(a). In all other uses of plot, the imaginary part is ignored. plot(a,b) plots vector b versus vector a. If a or b is a matrix, then the vector is plotted versus the rows or the columns of the matrix, depending on which matches the dimension of the vector. If a is a scalar and b is a vector,
6、 length(b) disconnected points are plotted. You can plot with various line types, plot symbols, and colors using plot(a,b,s) where s is a character string composed of one element from any or all of the three columns in the following table.For example, plot(a,b,c+:) plots a cyan dotted line with a pl
7、us symbol at each data point.plot(a,b,bd) plots a blue diamond at each data point, but does not draw any line. plot(a1,b1,s1,a2,b2,s2,.) combines the plots defined by the (a,b,s) triples. For example, plot(a,b,y-,a,b,go) plots the data twice, with a solid yellow line interpolating green circles at t
8、he data points.1. 如何设置 ezplot 函数绘图的颜色h=ezplot(sin(x)set(h,Color,red)2. matlab 填充颜色问题h=ezsurf(420-3*x-4*y)/4,50,70); set(h,facecolor,r);hold on; g=ezsurf(300-2*x-3*y)/2,50,70); set(g,facecolor,g)axis equal3. matlab 填充颜色问题ezmesh(x2+y2,-2*pi,2*pi, -2*pi,2*pi)colormap(1 0 0)4. 如何将一个图中多个封闭曲线内填充不同的颜色n = 6
9、;r = (0:n)/n;theta = pi*(-n:n)/n;X = r*cos(theta);Y = r*sin(theta);C = r*cos(2*theta);pcolor(X,Y,C)axis equal tight5. matlab 中如何对一条曲线和 X 轴之间的区域进行颜色的填充,比如一个高斯曲线下对应不同 X 段范围填充不同的颜close allx = 0:0.1:pi;y = sin(x);area(x,y,FaceColor,r);hold onx = pi:0.1:2*pi;y = sin(x);area(x,y,FaceColor,g);x = 2*pi:0.1:
10、3*pi;y = sin(x);area(x,y,FaceColor,b);axis(0,3*pi,-1,1)注意最后 x 轴坐标一定要设置,否则图像显示不完全。颜色的设置可以自己任意,将b,r等换成a b c格式的 RGB 色就可以。6. 关于 matlab 动画的问题h = 500; %h 为初始高度x = 0;figure;for t=0:.01:10y=h-0.5*10*t2; %y 为任意时刻小球离地的高度k=size(y);for i=1:kplot(x, y(i),ro);axis(-1, 1, 0, 500);M(:,i)=getframe;endendmovie(M,2,1)