Is this a correct application of a loop to measure a derivative?

3 vues (au cours des 30 derniers jours)
Abhi Ove
Abhi Ove le 18 Mar 2017
Hi All,
I have a velocity profile (v_phi) for a radial distance (r). From this velocity profile I am trying calculate the shear rate (y) which can be calculated by ( Eq 2 in Image):
y = ( d(v_phi) / d(r) ) - ( (v_phi) / r ) = r * ( ( d ( v_phi / r) / d(r) )
Please find the image of the equation from the papers attached,
I have implemented the equation as such,
~~~~
for i = 1: size(v_phi,1)
y (i) = ( r(i) ) * (( ( v_phi (i) / r(i) ) - ...
( v_phi (i+1) / r(i+1) ) ) / ( r(i+1) - r(i)) );
y1 (i) = ( ( ( v_phi(i) / r(i) ) - ( v_phi(i+1) / r(i+1) ) ) * ...
( v_phi (i) / r(i) ) );
end
~~~~
However it seems that y and y1 values are very different. I am just wondering, whether I am doing something wrong in the implementation and looking for help if possible.
Many thanks.
Data >>>>
v_phi = [36.99 37.00 35.78 31.43 26.91 23.32 19.46 16.97 14.49 12.12 10.42 8.52 7.25 6.06 5.11 3.92 3.30 2.54 2.11 1.42 1.46 1.46 0.97 0.63 0.63 0.51 0.40 0.91 0.24 0.36 0.63 0.71 0.45 0.26 0.74 ];
r = [3.59 3.76 3.94 4.12 4.29 4.47 4.65 4.82 5.00 5.18 5.35 5.53 5.71 5.88 6.06 6.24 6.41 6.59 6.76 6.94 7.12 7.29 7.47 7.65 7.82 8.00 8.18 8.35 8.53 8.71 8.88 9.06 9.24 9.41 9.50 ];

Réponse acceptée

Arvind Narayanan
Arvind Narayanan le 27 Mar 2017
Modifié(e) : Arvind Narayanan le 27 Mar 2017
Hi Abhi,
I understand that you are trying to use the finite difference method to calculate the derivative of v_phi w.r.t r. A few salient points I noticed about your code:
1) Your representation of the partial derivative of v_phi w.r.t r is only valid if r is the only independent variable of which v_phi is defined. If there are other variables involved, then d(v_phi) is not the same as partial derivative of v_phi.
2) Assuming that your representation is valid, I understand that y is the RHS of the equation and y1 is the LHS of the equation. If so, the representation of y1 is incorrect. The correct formula should be:
y1(i)= ( ( v_phi(i+1)-v_phi(i) / r(i+1)-r(i) ) - ( v_phi(i) / r(i) ) );
3) Ensure that the limits of the for loop are defined correctly between 1 and n-1, where n is the size of the array v_phi. Something like this:
v_phi = [36.99 37.00 35.78 31.43 26.91 23.32 19.46 16.97 14.49 12.12 10.42 8.52 7.25 6.06 5.11 3.92 3.30 2.54 2.11 1.42 1.46 1.46 0.97 0.63 0.63 0.51 0.40 0.91 0.24 0.36 0.63 0.71 0.45 0.26 0.74 ];
r = [3.59 3.76 3.94 4.12 4.29 4.47 4.65 4.82 5.00 5.18 5.35 5.53 5.71 5.88 6.06 6.24 6.41 6.59 6.76 6.94 7.12 7.29 7.47 7.65 7.82 8.00 8.18 8.35 8.53 8.71 8.88 9.06 9.24 9.41 9.50 ];
y=[];
y1=[];
for i = 1:1:size(v_phi,2)-1
y(i) = (r(i))*((( v_phi(i)/ r(i)) -( v_phi(i+1)/r(i+1)) )/(r(i+1)-r(i)) );
y1(i)= ( ( v_phi(i+1)-v_phi(i) / r(i+1)-r(i) ) - ( v_phi(i) / r(i) ) );
end
Ensure to define y and y1 as empty arrays before the for loop.
Regards,
Arvind

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by