⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig4_4.m

📁 good code for matlab by mili , i than you
💻 M
字号:
% Illustration of the Taylor series for one variable
%  Optimization Using MATLAB
%	Dr. P.Venkataraman
%
%	section 4.2.3
% The graphics are generated in the code

syms x
f= 12 + (x-1)*(x-1)*(x-2)*(x-3);

% taylor is a symbolic function that generates
% the taylor approximation approximation
% usage here taylor(function,order,point t which to expand) 
% the functions are expanded about the point 2.5

t1=taylor(f,1,2.5); % expansion with first term

t2=taylor(f,2,2.5);  % linear expansion
t3=taylor(f,3,2.5);  % quadratic expansion
t6=taylor(f,6,2.5);	% fifth order expansion

xd=0:.05:4;	
fval=double(subs(f,x,xd)); % original function

c1=plot(xd,fval);
set(c1,'LineWidth',2,'Color','r', 'LineStyle','-');
hold on

ezplot(t1,[0,4]); %plot constant approximation
ezplot(t2,[0,4]); % plot linear expansion
ezplot(t3,[0,4]); % plot quadratic expansion
ezplot(t6,[0,4]); % plot fith order expansion

text(0.5,12,'constant');
text(0.75,13.5,'linear')
text(2.5,17,'fifth-order and original')
text(0.5,22,'quadratic');
grid

xlabel('x')
ylabel('f and Taylor expansion about 2.5')
title('Approximation using Taylor series')



hold off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -