MATLAB: How to extrapolate to the point of intersection

data fittingextrapolationMATLAB

I have the following data:
x=[0.100 0.071 0.051 0.036 0.026 0.019 0.013 0.094 0.0067 0.0048 0.0034 0.0024 0.0017 0.0012 0.00088 0.00063];
y1=[25.2 24.5 23.9 23.3 22.8 22.3 21.7 21.4 21.2 20.3 20.1 19.7 19.4 19.2 18.7 18.4];
y2=[2.85 2.77 2.66 2.64 2.55 2.49 2.44 2.45 2.48 2.52 2.63 2.87 3.17 3.67 4.31 5.18];
I would like to calculate x value for the hypothetical intersection point shown in the figure:
Thank you in advance,
John

Best Answer

This works:
use = (x >= 5E-4) & (x <= 3E-3);
xuse = x(use);
y1use = y1(use);
y2use = y2(use);
B1 = polyfit(log(xuse), log(y1use), 1);
y1fit = exp(polyval(B1, log([1E-5 xuse])));
B2 = polyfit(log(xuse), log(y2use), 1);
y2fit = exp(polyval(B2, log([1E-5 xuse])));
xint = exp( (B2(2) - B1(2))/(B1(1)-B2(1)) ); % Calculate X-Intercept
yint = exp(polyval(B1, log(xint))); % Calculate Y-Intercept
figure(1)
loglog(xuse, y1use, 'db', 'MarkerFaceColor','b')
hold on
plot(xuse, y2use, 'sr', 'MarkerFaceColor','r')
plot([xuse 1E-5], y1fit, ':b', [xuse 1E-5], y2fit, ':r')
plot(xint, yint, 'pg', 'MarkerSize',10 , 'MarkerFaceColor','g')
hold off
axis([1E-5 1E-2 1 100])
format short eng
producing:
xint =
4.6495e-05
yint =
16.1025
These should be close to the values you get with your entire vector. It plots correctly.
EDIT 1 If you want to use a nonlinear approximation to the power function, this will produce more accurate results:
objfcn = @(b,x) exp(b(1)) .* x.^b(2);
B1 = fminsearch(@(b) norm(y1use - objfcn(b, xuse)), [1; 1]);
y1fit = objfcn(B1, [xuse 1E-5]);
B2 = fminsearch(@(b) norm(y2use - objfcn(b, xuse)), [1; 1]);
y2fit = objfcn(B2, [xuse 1E-5]);
xint = exp(B1(1)-B2(1)) .^ (1/(B2(2)-B1(2)));
yint = objfcn(B1, xint);
producing:
xint =
5.2181e-05
yint =
16.2103
EDIT 2 Added plot, and updated both ‘xint’ and ‘yint’ results to incorporate the recently-edited ‘x’ vector. (The code did not change.)