matlab画交点坐标
来源:学生作业帮 编辑:大师作文网作业帮 分类:数学作业 时间:2024/11/17 05:09:51
matlab画交点坐标
x=0:0.1:10;
f=x./(x+2);
h=1./(1+10.*(x-2).^2);
g=2.^(-x);
plot(x,f,x,h,x,g);
axis([0 1 -1 1]);
怎么在图中显示出交点坐标(保留3位小数)?
或求出交点坐标
x=0:0.1:10;
f=x./(x+2);
h=1./(1+10.*(x-2).^2);
g=2.^(-x);
plot(x,f,x,h,x,g);
axis([0 1 -1 1]);
怎么在图中显示出交点坐标(保留3位小数)?
或求出交点坐标
f=@(x)x./(x+2);
h=@(x)1./(1+10.*(x-2).^2);
g=@(x)2.^(-x);
fplot(@(x)[f(x),h(x),g(x)],[-0.25 15]);
%求交点
xfh=[];xfg=[];xhg=[];
for x0=[0,1,2,3,8]
xfh(end+1)=fsolve(@(x)f(x)-h(x),x0);
xfg(end+1)=fsolve(@(x)f(x)-g(x),x0);
xhg(end+1)=fsolve(@(x)h(x)./g(x)-1,x0);
end
xfh=unique(xfh);yfh=f(xfh);
xfg=unique(xfg);yfg=f(xfg);
xhg=unique(xhg);yhg=h(xhg);
hold on
plot(xfh,yfh,'o',xfg,yfg,'d',xhg,yhg,'^')
for i=1:length(xfh)
text(xfh(i),yfh(i),[' (',num2str(xfh(i)),',',num2str(yfh(i)),')'])
end
for i=1:length(xfg)
text(xfg(i),yfg(i),[' (',num2str(xfg(i)),',',num2str(yfg(i)),')'])
end
for i=1:length(xhg)
text(xhg(i),yhg(i),[' (',num2str(xhg(i)),',',num2str(yhg(i)),')'])
end
h=@(x)1./(1+10.*(x-2).^2);
g=@(x)2.^(-x);
fplot(@(x)[f(x),h(x),g(x)],[-0.25 15]);
%求交点
xfh=[];xfg=[];xhg=[];
for x0=[0,1,2,3,8]
xfh(end+1)=fsolve(@(x)f(x)-h(x),x0);
xfg(end+1)=fsolve(@(x)f(x)-g(x),x0);
xhg(end+1)=fsolve(@(x)h(x)./g(x)-1,x0);
end
xfh=unique(xfh);yfh=f(xfh);
xfg=unique(xfg);yfg=f(xfg);
xhg=unique(xhg);yhg=h(xhg);
hold on
plot(xfh,yfh,'o',xfg,yfg,'d',xhg,yhg,'^')
for i=1:length(xfh)
text(xfh(i),yfh(i),[' (',num2str(xfh(i)),',',num2str(yfh(i)),')'])
end
for i=1:length(xfg)
text(xfg(i),yfg(i),[' (',num2str(xfg(i)),',',num2str(yfg(i)),')'])
end
for i=1:length(xhg)
text(xhg(i),yhg(i),[' (',num2str(xhg(i)),',',num2str(yhg(i)),')'])
end