Matlab中用fzero求交点
我面临一个问题,使用fzero来查找两个图相交的x值Matlab中用fzero求交点,matlab,Matlab,我面临一个问题,使用fzero来查找两个图相交的x值两组数据位于同一个图形上。数据集1 z = sqrt(D.^2 + x.^2) zcost = CS1*z; landcost = C01*(L-x); totcost = @(x) zcost + landcost; figure(2) plot(x,totcost(x),'k-'); 数据集2 C2sea = CS2*(1+0.5*alpha*ee*D)*(sqrt(x.^2+(1+ee.^2)*D.^2)); C2land = C02*
两组数据位于同一个图形上。
数据集1
z = sqrt(D.^2 + x.^2)
zcost = CS1*z;
landcost = C01*(L-x);
totcost = @(x) zcost + landcost;
figure(2)
plot(x,totcost(x),'k-');
数据集2
C2sea = CS2*(1+0.5*alpha*ee*D)*(sqrt(x.^2+(1+ee.^2)*D.^2));
C2land = C02*(L-x);
C2cost = @(x) C2sea + C2land;
figure(2) %figure 2
plot(x,C2cost(x),'r-');
我无法复制您的代码,因为您没有包括D、CS1等的值,但您可以执行以下操作:
% Make up some arbitrary functions
x = linspace(0,10);
y1 = @(t) (t - 3).^2 + 10;
y2 = @(t) (t - 7).^2 + 15;
% Plot them
plot(x, y1(x) ,x, y2(x))
ylim([0 50])
% Define another function of the difference between y1 and y2
% this difference should be zero when the functions intersect
z = @(t) y1(t) - y2(t);
fzero(z, 5)
其中:
ans =
5.6250