MATLAB: How to find the maximum vertical distance between two curves?

1.4k Views Asked by At

I am interested in finding the x value at which the vertical distance between two curves is maximum. I don't know how to do this in Matlab (see the figure below for the graph)

Graph

I have my functions defined to be:

y1 = (1 - exp(-5))*exp(-x/50);
y2 = (1 - exp(-5000/1600))*exp(-x/250);
x = 10:300;

Does anyone know how I can locate the maximum vertical distance between these two graphs in the interval 10 to 300? Thank you for your time

1

There are 1 best solutions below

1
On BEST ANSWER

[M,I] = max(abs(y1-y2)) gives the desired maximum value M and the corresponding first index I.

x = 10:300;
y1 = (1 - exp(-5))*exp(-x/50);
y2 = (1 - exp(-5000/1600))*exp(-x/250);
[M,I] = max(abs(y1-y2));
display([M,x(I)])  # return: 0.50663   103.00000