Plot conflicts with mathematical calculation

I have a model function shown as below:
F=((b.*A-(x-a).*B)./((x-a).^2+b^2-A^2-B^2))+e;
From the mathematical calculation, I calculate its first derivative, and get [B(x-a-bA/B)^2-(b^2-B^2)(A^2+B^2)/B]/[(x-a)^2+b^2-A^2-B^2]^2,
so if b^2>B^2 and B>0,then the first derivative has the possibility to be zero, which gives the extreme points. However, if I set the parameters to be b<B and B>0, I can still get maximum and minimum values shown below.
I am not sure what mistakes I make. Another point is that if I set the range to be (0,2000,50000) and then set it to be (1000,1500,12500), it is not a zoomed-in picture as what I would expect. Actually the values change a lot, which is shown below.
Thanks a lot for all the advice. Below is my script. Thanks.
a=2000;
b=700;
A=800;
B=790;
e=10;
x=linspace(0,2000,50000);
F=((b.*A-(x-a).*B)./((x-a).^2+b^2-A^2-B^2))+e;
plot(x,F)

 Accepted Answer

There are two poles. The function is undefined when the denominator is zero. The only reason it looks like the extrema vary is simply an artifact of the discrete locations at which the function is being evaluated.
If you evaluate the function at the exact location (at least as close as we can get with FP rounding), you'll get a good illustration:
a=2000;
b=700;
A=800;
B=790;
e=10;
% evaluate F at the calculated location
x = a - (A^2 + B^2 - b^2)^(1/2); % 1120.17
% x = a + (A^2 + B^2 - b^2)^(1/2); % 2879.83
F = ((b.*A-(x-a).*B)./((x-a).^2 + b^2 - A^2 - B^2)) + e
F = Inf
x = x+eps(x); % make the smallest possible step to the right
F = ((b.*A-(x-a).*B)./((x-a).^2 + b^2 - A^2 - B^2)) + e
F = -2.6952e+15
What are the maximum and minimum values? They're the same as they are at every sort of singularity. They're +Inf and -Inf. Does it really matter what the extrema are in that vicinity?

5 Comments

Thanks a lot. Now I get it. So it is actually caused by the denominator to be zero, not a true maximum or minimum value right? The model that I have should have a s-shape, right, if having a good estimation for different parameters.
Yes, I totally understand what you mean. In my case, this model is a function derived from physical theory, and I get the experimental data, so I want to fit my data to this model to extract these parameters' values. So x range will not be this big, and it will only be from 1970.3 to 1971, and I feel if the parameters have some specific values, it is still an s-shape? Or maybe I am wrong? The extreme points from the first derivative to be 0 is not the same as the case if I directly set the denominator to be 0?(Ignore the existing parameters settings, I just try with some values to gain some understanding)
I'm not really sure I follow where you're going with this, but over such a small interval between the poles (1970-1971), the function is well-behaved and essentially linear, so I would imagine you would be able to do what you need.
If the denominator is 0 then there are four possibilities:
  • the numerator might be negative. In this case the function value is negative infinity
  • the numerator is positive. In this case the function value is positive infinity
  • the numerator is 0. In this case you need to take the limits to figure out what the situation is
  • the numerator is complex valued. In this case the result is a combination of the above
Anywhere that the denominator is defined and non-zero, you can use the derivative of the numerator to determine the critical points (but whether they correspond to maxima or minima can depend on the sign of the denominator)
Thanks a lot, yes, I agree with you. After carefully adjusting the parameters, I can get the s-shape as what I expect. Thank you both.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2020b

Tags

Asked:

on 26 Apr 2022

Commented:

on 26 Apr 2022

Community Treasure Hunt

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

Start Hunting!