How can I find the intersection from two fitting line?
24 views (last 30 days)
Show older comments
I have two fitting models as below:
Linear model:
f(x) = a*(sin(x-pi)) + b*((x-10)^2) + c
Coefficients (with 95% confidence bounds):
a = 1.827 (-0.4519, 4.106)
b = -0.1606 (-0.2539, -0.06737)
c = 22.76 (17.64, 27.88)
And
Linear model Poly3:
g(x) = p1*x^3 + p2*x^2 + p3*x + p4
Coefficients (with 95% confidence bounds):
p1 = 24.22 (21.22, 27.23)
p2 = -305.6 (-342.3, -268.8)
p3 = 1287 (1137, 1437)
p4 = -1793 (-1996, -1589)
How can I find the intersections of these models(x is between 3:4)?
0 Comments
Accepted Answer
Star Strider
on 20 Dec 2016
First, plot the two functions. That reveals only one intersection. Then create anonymous functions from them, and a third anonymous function that subtracts them, and use fzero to find the zero-crossing. This gives you the intersection at 4.7157.
The Code:
a = 1.827;
b = -0.1606;
c = 22.76;
f = @(x) a*(sin(x-pi)) + b*((x-10).^2) + c;
p1 = 24.22;
p2 = -305.6;
p3 = 1287;
p4 = -1793;
g = @(x) p1*x.^3 + p2*x.^2 + p3*x + p4;
fg = @(x) f(x) - g(x);
xint = fzero(fg, 1)
x = linspace(4, 5);
figure(1)
plot(x, fg(x))
hold on
plot(xint, 0, 'pr', 'MarkerFaceColor','g')
hold off
grid
figure(2)
plot(x, f(x))
hold on
plot(x, g(x))
plot(xint, f(xint), 'pr', 'MarkerFaceColor','g')
hold off
grid
xint =
4.7157
0 Comments
More Answers (1)
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!