How can I find and intersection values between line and polynomial equation ?

17 views (last 30 days)
Hi all,
First of all I have gathered some data from my experiments witch looks something like this:
Now I do a linearization for my data using Matlab command:
y=feval(fit(a(l:o,1,1),a(l:o,2,1),'poly1'),a(l:o,1,1));
Results looks like this:
Now I do a interpolation using for example 5th order poly and get this:
I calculate the peak value and calculate -3dB value of peak value and get a line as you can see in the image:
Now my question is, what is the fastest and the best function to find the intersection x values of the 5th order polynomial and the line?
  3 Comments
David B
David B on 7 Mar 2013
Then why did I saw the pictures in the preview window? I thought the post would become the same as in the preview window when I post it :/, that is kind of misleading.
Randy Souza
Randy Souza on 12 Apr 2013
Edited: Randy Souza on 12 Apr 2013
FYI, PNGs are fine, but the markup to embed images is two angle brackets:
<<image-url>>
I edited David's post to use the correct markup.

Sign in to comment.

Answers (2)

Ryan Livingston
Ryan Livingston on 7 Mar 2013
Provided that you can evaluate the fit object like a function, I think you can but I'm not too familiar with those (they can be passed to FEVAL I think), you can write a small anonymous function like:
@(x)polyFun(x) - lineFun(x)
which evaluates the difference between the two, where "polyFun" returns the value of your 5th degree fit and "lineFun" returns the value of your line. Then that can be used in FZERO:

David B
David B on 8 Mar 2013
clear all;
clear a;
dB=10^(-3/20);%dB value
pr=6e6; %starting value
pb=6.9e6; %end value
l=1;
%read data from file
a(:,:,1)=dlmread('C:\experiments\l_W1_0V.dat');
while a(l)<pr %find the start value
l=l+1;
end
o=l;
while a(o)<pb %find the end value
k=size(a)-1;
if o>k
break
end
o=o+1;
end
%linearization
y=feval(fit(a(l:o,1,1),a(l:o,2,1),'poly1'),a(l:o,1,1));
plot(a(l:o,1,1),a(l:o,2,1))
plot(a(l:o,1,1),a(l:o,2,1),a(l:o,1,1),y)
plot(a(l:o,1,1),a(l:o,2,1),a(l:o,1,1),a(l:o,2,1)-y)
plot(a(l:o,1,1),a(l:o,2,1)-y)
%interpolate using polynome
x=feval(fit(a(l:o,1,1),a(l:o,2,1)-y,'poly5'),a(l:o,1,1));
polinomasX=fit(a(l:o,1,1),a(l:o,2,1)-y,'poly5');
plot(a(l:o,1,1),x)%polynome function plot
Rmax=max(x);%find max value of the polinome
R=Rmax*dB;
dR=Rmax-R; %find delta R
%plot(a(l:o,1,1),x,a(l:o,1,1),R)
s=a(l):0.01e6:a(o);%line x points
Rt=zeros(size(s));
Rt(Rt==0)=R;%line y points
plot(s,Rt);
hold on
plot(a(l:o,1,1),x,s,Rt)%intersection between line and polynome
hold off
This is my .m file that I use for data management.
x is an array of the y values of the polynome. I used a Matlab command
c=knnsearch(x,R)
witch gave me a number that is the number of the array element witch corresponds closest to the R value. By adding this
intersection=(a(c+1)+a(c))/2
to matlab I get a very good answer for the first point. Now, how can I find the second point on intersection?

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!