how to compute premitive function
1 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/814724/image.jpeg)
0 个评论
回答(1 个)
Walter Roberson
2021-11-27
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 个评论
Walter Roberson
2021-11-27
Then you cannot restore the original function; you can only restore to within a constant offset.
Walter Roberson
2021-11-27
syms x
A = sin(x)^2
B = 1 - cos(x)^2
C = -cos(x)^2
fplot([A, C], [-2*pi 2*pi])
dA = diff(A,x)
dB = diff(B,x)
dC = diff(C,x)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/815249/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/815254/image.png)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!