how to compute premitive function

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

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Nov. de 2021

0 votos

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 comentarios

james sinos
james sinos el 27 de Nov. de 2021
Editada: james sinos el 27 de Nov. de 2021
i am ok with that explnation .
what is the solution to get the write function .?? it should have a trick for that
Walter Roberson
Walter Roberson el 27 de Nov. de 2021
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.
This does depend upon you still having access to the original function in order to be able to evaluate it at some point. If you no longer have access to the original function, then there is nothing you can do.
james sinos
james sinos el 27 de Nov. de 2021
No i dont have access to original function its abvious
Walter Roberson
Walter Roberson el 27 de Nov. de 2021
Then you cannot restore the original function; you can only restore to within a constant offset.
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 27 de Nov. de 2021

Comentada:

el 27 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by