1个回答
展开全部
function y=sss()
a=0;b=pi;
dif=(temp(b)-temp(a))/(b-a);
x0=a:0.01:b;
y0=temp(x0);
widths=pi/4;
n=length(x0);
for i=1:n
x1=(x0(i)-widths):0.01:(x0(i)+widths);
dd=dtemp(x0(i));
y1=(x1-x0(i))*dd+y0(i);
plot(x0,y0,'-r');
hold on;
axis([0 pi 0 5]);
plot([a b],[temp(a),temp(b)],'-b');
plot(x1,y1,'-.k');
tutu = legend('f(x)=x+sin(x)','端点割线','切线');
set(tutu,'fontname','宋体','fontsize',10,'FontWeight','demi');
title('用函数f(x)=x+sin(x)验证Lagrange中值定理',...
'fontname','宋体','fontsize',9,'FontWeight','demi','Color','black');
plot(x0(i),y0(i),'-ro','markersize',4);
pause(0.001);
hold off;
if abs(dd-dif)<0.01
ta=[' \leftarrow 该点满足Lagrange中值定理','(',num2str(x0(i)),',',num2str(x0(i)),')'];
text(x0(i),y0(i),ta,'FontSize',9);
return;
end
end
function y=temp(x)
n=length(x);
for i=1:n
y(i)=x(i)+sin(x(i));
end
function y=dtemp(x)
syms a;
yt=diff(temp(a));
y=subs(yt,'a',x);
a=0;b=pi;
dif=(temp(b)-temp(a))/(b-a);
x0=a:0.01:b;
y0=temp(x0);
widths=pi/4;
n=length(x0);
for i=1:n
x1=(x0(i)-widths):0.01:(x0(i)+widths);
dd=dtemp(x0(i));
y1=(x1-x0(i))*dd+y0(i);
plot(x0,y0,'-r');
hold on;
axis([0 pi 0 5]);
plot([a b],[temp(a),temp(b)],'-b');
plot(x1,y1,'-.k');
tutu = legend('f(x)=x+sin(x)','端点割线','切线');
set(tutu,'fontname','宋体','fontsize',10,'FontWeight','demi');
title('用函数f(x)=x+sin(x)验证Lagrange中值定理',...
'fontname','宋体','fontsize',9,'FontWeight','demi','Color','black');
plot(x0(i),y0(i),'-ro','markersize',4);
pause(0.001);
hold off;
if abs(dd-dif)<0.01
ta=[' \leftarrow 该点满足Lagrange中值定理','(',num2str(x0(i)),',',num2str(x0(i)),')'];
text(x0(i),y0(i),ta,'FontSize',9);
return;
end
end
function y=temp(x)
n=length(x);
for i=1:n
y(i)=x(i)+sin(x(i));
end
function y=dtemp(x)
syms a;
yt=diff(temp(a));
y=subs(yt,'a',x);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询