x=[0:.01:10];
y=(x.^2).*(exp(-x));
plot(x,y), grid
y1=max(y);
xlabel(\'TIME\');
ylabel(\'CONCENTRATION IN BLOOD\');
title(\'CONCENTRATIN OF SUSTANCE IN BLOOD vs TI
One key issue here is that there are multiple points on your plot where y = 0.3
. If you want to find all of them in a simple way, you can follow these steps:
y
, so that the points you want to find become zero crossings.y
values on either side of the zero crossings, compute the percentage of the difference between them at which the value 0.3 lies. This essentially performs a linear interpolation between the two points on either side of the zero crossing.x
for the zero crossing.And here's the code along with a plot to show the points found:
>> yDesired = 0.3;
>> index = find(diff(sign(y-yDesired)));
>> pctOfDiff = (yDesired-y(index))./(y(index+1)-y(index));
>> xDesired = x(index)+pctOfDiff.*(x(index+1)-x(index))
xDesired =
0.8291 3.9528
>> plot(x,y);
>> hold on;
>> plot(xDesired,yDesired,'r*')
>> xlabel('x');
>> ylabel('y');