how to compute premitive function

7 views (last 30 days)
james sinos
james sinos on 27 Nov 2021
Commented: Walter Roberson on 27 Nov 2021
lets say :
i have dq the derivative of the function q (r) , starting from dq i would like to compute the original q function using dq that i have
i dont think i can use integral beause it gaves a scalar of integral value . while i need the original function .
so what are different ways to computing it .
i did performe usind finite difference method as following:
Dr= spdiags([-ones(size(r)) ones(size(r))]/hr,[-1 0],Nr,Nr);
dq = Dr*q then q= Dr\dq;
i applied it on simple functions to check for it : dq= cos(r) exact_q=sin( r)
so the code is:
r=-pi/2:pi/24:pi/2;
r = r(:);
Nr=length(r);
hr=r(2)-r(1);
Exact_q=sin(r);
dq=cos(r);
Dr = spdiags([-ones(size(r)) ones(size(r))]/hr,[-1 0],Nr,Nr);
q=Dr\dq;
comparing exact_q =sin ( r) to the computed q , i got the same shape but with large difference .
in the graph in red is computed q=Dr\dq , the blue is sin(r) , so it seems does'nt work , if there are other method

Answers (1)

Walter Roberson
Walter Roberson on 27 Nov 2021
It is working as well as you can expect.
Remember, the derivative of f(x)+constant is d f(x)/dx + d constant/dx and d constant/dx is 0, so the derivative of f(x)+constant is f'(x) + 0 . All knowledge of what the constant value is has been lost. Now integrate that f'(x) back and you get f(x) + 0*x which is f(x) + 0 not f(x) + constant for that original constant.
Therefore if you take the derivative and integrate it back, you lose any constant -- and so the calculated value can be an arbitrary constant away from the original function.
It looks to me as if in your case, the constant is 1.
If you were to take the original function evaluated at any one point, and take the difference with the new function evaluated at the same point, then the difference is the constant that you should add to the new function.
  5 Comments
Walter Roberson
Walter Roberson on 27 Nov 2021
syms x
A = sin(x)^2
A = 
B = 1 - cos(x)^2
B = 
C = -cos(x)^2
C = 
fplot([A, C], [-2*pi 2*pi])
dA = diff(A,x)
dA = 
dB = diff(B,x)
dB = 
dC = diff(C,x)
dC = 
We know from the trig identities that and therefore so A and B are the same function. C is then the same function minus 1, which is a constant offset. You can see from the fplot() that the two have the same shape but a constant difference.
Now look at the derivatives and see that they are all the same. If you were to pass dA and dC into your reconstruction function, since they are the same, there is no way the function would be able to deduce whether the original function was A or C.

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!