How to get the intersection points of a line and a curve which was fit to data?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Khanh
le 24 Oct 2014
Modifié(e) : Hussein Qenawy
le 13 Avr 2019
Hi,
I have a line and a curve that was fit to a data. I also get Coefficients of Equation of the Curve, but don't know how to find its equation to make two equations equal to find the points of the tangency. Could someone give me some recommends?
Here is my code:
clc
array=[515 525 561 600 632 700 761 800 900 1000 1014 1750;
0 150 300 394 450 540 600 631 696 745 750 865];
x=linspace(array(1,1),array(1,end),101)
y=interp1(array(1,:),array(2,:),x,'pchip')
x=transpose(x)
y=transpose(y)
%
f=fit(y,x,'pchip')
a=coeffvalues(f)
plot(f,y,x)
hold on
% Equation of line that pass through origin
x1=0:1000;
slope=tan(51.5*pi/180);
y1=slope*x1
plot(x1,y1)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145841/image.png)
0 commentaires
Réponse acceptée
Andrei Bobrov
le 24 Oct 2014
Modifié(e) : Andrei Bobrov
le 25 Oct 2014
one way with Curve Fitting Toolbox
array=[515 525 561 600 632 700 761 800 900 1000 1014 1750;
0 150 300 394 450 540 600 631 696 745 750 865];
x = array([2 1],:)';
f = fit(x(:,1),x(:,2),'cubicinterp');
df = fit(x(:,1),differentiate(f,x(:,1)),'cubicinterp');
xx = fzero(@(x)f(x)/x - df(x),[1 750]);
x1 = linspace(x(1,1),x(end,1),300);
plot(x1,f(x1),x1,x1*df(xx),xx,f(xx),'ro');
well, more
f = fit(x(:,1),x(:,2),'cubicinterp');
df = fit(x(:,1),differentiate(f,x(:,1)),'cubicinterp');
k = tand(10);
xx = fzero(@(x)df(x) - k,[1 x(end,1)]);
you line: y = k*x + b
b = f(xx) - k*xx;
x1 = linspace(x(1,1),x(end,1),300);
plot(x1,f(x1),x1,k*x1 + b,xx,f(xx),'ro');
8 commentaires
Hussein Qenawy
le 13 Avr 2019
Modifié(e) : Hussein Qenawy
le 13 Avr 2019
Good evening Mr andrie.. Iam studying matlab now... I have 4 problems need to solve by matlab. I need your help to solve these problems for money.. If it's OK for you.. Contact me whatsapp 0097430272448. Thanks
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Smoothing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!