Finding where plots may cross with octave / matlab

萝らか妹 提交于 2019-11-29 11:30:51

Try this function from the File Exchange, it seems to work just fine in Octave. x0 are the frequencies of interest:

>> [x0,y0,iout,jout] = intersections(freq,amp_orig,freq,amp_inv)
x0 =

   30.000
   30.000
   42.500
   55.000
   64.286
   80.000

y0 =

   4.0000
   4.0000
   4.0000
   4.0000
   4.0000
   4.0000

iout =

   2.0000
   2.0000
   3.2500
   4.5000
   5.4286
   7.0000

jout =

   2.0000
   2.0000
   3.2500
   4.5000
   5.4286
   7.0000

Should you have access to Matlabs Mapping Toolbox, your problem can be solved easily using the function polyxpoly(). It will find the intersections of two graphs. They do not even have to be lines, also polygons work. Here is an example for your case:

%graphics_toolkit gnuplot %use this for now it's older but allows zoom
freq=[20,30,40,50,60,70,80];
amp_orig=[2,4,3,7,1,8,4];
amp_inv=[6,4,5,1,7,0,4];

plot(freq,amp_orig,'-bo')
hold on
plot(freq,amp_inv,'-r*')
xlabel ('Frequency');
ylabel ('Amplitude');

%// find and add intersections
[xi,yi] = polyxpoly(freq,amp_orig,freq,amp_inv)
plot(xi, yi,'ro','markersize',20) %// draw the red circles automatically :-)

The result looks like this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!