Taking derivative an array which is a numerical value with respect to another array
이전 댓글 표시
Hello,
I need to take a derive of an array (1*101) (which is numerical not analytical)
with respect to another array (1*101). How could I do that in Matlab? Any help please?
댓글 수: 1
S. Gopal
2018년 1월 31일
The same problem I am facing....please anybody help
채택된 답변
추가 답변 (1개)
pfb
2015년 5월 2일
if f is the vector representing f(x) and x contains the corresponding abscissae
df = diff(f)./diff(x)
note that this has one less element than f and x. You can choose
xd = (x(1:end-1)+x(2:end))/2
(i.e. the halfway points) as the corresponding abscissae.
댓글 수: 4
pfb
2015년 5월 2일
What I suggest should work. If your numerical values for u are in a vector "u" and those for x are in a vector "x", of the same size as u, then
du = diff(u)./diff(x)
For instance, if u=f(x)=x^3 (I know that u here is "analytical", but for the purpose of the example it is numerical).
x = linspace(1,3,100);
u = x.^3;
then you get the derivative as
du = diff(u)./diff(x);
You can check this in a plot. As I said above, we have to assign the abscissae to du.
xd = (x(1:end-1)+x(2:end))/2;
Then plot dots for the numerical derivative
plot(xd,du,'.');
Hold the plot
hold;
and superimpose the (known, in this case) analytical derivative
plot(x,3*x.^2,'r');
Mohammad Abouali
2015년 5월 3일
편집: Mohammad Abouali
2015년 5월 3일
Either use, sided stencil on the boundaries, or if you have boundary conditions use them to set some sort of ghost/dummy nodes.
If you are trying to handle the advective terms u.du/dx+v.du/dy ... in NS equation I suggest that you read Numerical Simulation in Fluid Dynamics: A Practical Introduction It gives a very nice introduction to numerical solutions of NS equations.
You can also look at some of the references in http://www.sciencedirect.com/science/article/pii/S1877050913003530
Meva
2015년 5월 3일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!