Message Boards Message Boards

0
|
5328 Views
|
11 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Calculate the derivative from experimental data?

Posted 2 years ago

I have a list of experimental data coming from surface measurement in the form of {x,y,z}. I want to calculate the following formula in Mathematica. enter image description here I tried to write this code but it clearly doesn’t work.

enter image description here

thank you in advance for helping me.

(very first elements of my data : {0.00505051, 0., -18.164}, {0.010101, 0., -14.5719}, {0.0151515, 0., -9.9892}, {0.020202, 0., -5.792}, {0.0252525, 0., -1.7631}, {0.030303, 0., 0.9439})

POSTED BY: nahal ghanadi
11 Replies

Here is how I would transform your data into cylindrical coordinates:

dataForInterpolate = 
  yourData /. {x_, y_, z_} :> 
    With[{theta = ArcTan[x, y]}, {{Cos[theta], Sin[theta]}, z}];

You could also use CoordinateTransform[.....]

I am not familar with the Polar Spectrum graph.

POSTED BY: W. Craig Carter

I advise using Interpolation and NIntegrate if your data is smooth. Otherwise, if there is noise in your data, the derivatives will be noisy and you will probably want to smooth the data and use BSplineFunction.

Here is an example using Interpolation.

  1. You will need to arrange your data so that it corresponds to what Interpolation operates on:

    yourData = {{0.00505051, 0., -18.164}, {0.010101, 
       0., -14.5719}, {0.0151515, 0., -9.9892}, {0.020202, 
       0., -5.792}, {0.0252525, 0., -1.7631}, {0.030303, 0., 0.9439}}
    
    dataForInterpolate = yourData /. {x_, y_, z_} :> {{x, y}, z}
    

Unfortunately, we don't have enough of your data to continue, so here is an example with "example data"

exampleData = 
 Flatten[
  Table[ {{x, y}, Sin[x] Cos[y]}, {x, 0, 1, .01}, {y, 0, 1, .01}], 1]

zInterpolation = Interpolation@exampleData

Get interpolators for derivatives:

dzdxInterpolation = Derivative[1, 0][zInterpolation]
dzdyInterpolation = Derivative[0, 1][zInterpolation]

Numerically integrate:

NIntegrate[
 Sqrt[1 + dzdxInterpolation[x, y]^2 + dzdyInterpolation[x, y]^2 ], {x,
   0, 1}, {y, 0, 1}]

Compare:

With[{dx = D[Sin[x] Cos[y], x ], dy = D[Sin[x] Cos[y], y ] },
 NIntegrate[Sqrt[1 + dx^2 + dy^2], {x, 0, 1}, {y, 0, 1}]
 ]
POSTED BY: W. Craig Carter
Posted 2 years ago

I am so grateful for your time and help. I applied your method to my calculations, but there is an error! I will attach the link for downloading my full data. Can you please check the example data in this case? Thank you so much in advance

exampleData = Flatten[Table[{{x, y}, f {x, y}}, {x, 0, 1, .01}, {y, 0, 1, .01}], 1] 

https://drive.google.com/file/d/1t0ZWf6BdzatNFC9DIr4yqulEz6c2fCe8/view?usp=sharing

POSTED BY: nahal ghanadi
exampleData = Flatten[Table[{{x, y}, f {x, y}}, {x, 0, 1, .01}, {y, 0, 1, .01}], 1]

Has a syntax error f{x,y} should be f[x,y] if f is a function that takes two arguments. I will check your data sometime later.

POSTED BY: W. Craig Carter

Your data is a bit noisy which is normal for experimental data:

yourData = Import["~/tmp/ASmappa-niccolini90-0.dat", "TSV"];

you will want to use your path to your data.

dataForInterpolate = yourData /. {x_, y_, z_} :> {{x, y}, z};

zInterpolation = Interpolation@dataForInterpolate

Interpolate complains that your data is not on a regular (i.e., rectangular grid) so it reduces the order of interpolation.

Plot3D[zInterpolation[x, y], {x, 0.005, 5}, {y, 0, 3.95`}]

That means that your first-order derivatives will be extra noisy. However, we can proceed:

dzdxInterpolation = Derivative[1, 0][zInterpolation]
dzdyInterpolation = Derivative[0, 1][zInterpolation]

NIntegrate[
 Sqrt[1 + dzdxInterpolation[x, y]^2 + dzdyInterpolation[x, y]^2], {x, 
  0.005, 5}, {y, 0, , 3.95`}]

Complains that convergences is slow. This is likely from your derivatives. Integrate prints a result and an error estimate.

Possible fixes are to resample your data onto a regular grid, smooth a bit, and use Splines to approximate your data.

POSTED BY: W. Craig Carter
Posted 2 years ago

Thank you so much for your help. Have applied your method and now everything is working just fine. I have one more question and I would be grateful if you can advise me on this as well. I have to calculate a parameter that in order to do so my data must be transformed into polar coordinates (data is lots of points in x,y,z format) and it is using Angular Spectrum. The result is shown in the polar spectrum graph (I Guess the other name of the graph is rosette graph but I am not sure). Do you have any suggestions on how the code for plotting the graph might be?

Thank you so much in advance. enter image description here

POSTED BY: nahal ghanadi

Use the following code to construct $f$ from you data.

f[data_] := Interpolation(data, Method -> "RBF");

If you post your data together with $A$ and $A_R$ (i.e. the domain of integration), then I can show you a complete code on how to evaluate your formula numerically using NIntegrate.

POSTED BY: Ta'a Nwa Dombou
Posted 2 years ago

Thank you so much for your help. I am developing a platform based on the data that I have to calculate some surface parameters. so I don't have a specific number for A and Ar. that is why I used dimx and dimy to limit the surface as desired. the data file was not readable in here so you can download it from the following link. I appreciate your help in advance. enter link description here

POSTED BY: nahal ghanadi

Click on the link which is in my post and It will bring you to the Wiki page on RBF interpolation. I

POSTED BY: Ta'a Nwa Dombou

You must first reconstruct the surface $z = f(x,y)$. One way to do it is via Radial Basis Function (RBF) interpolation. One you are satisfied with your interpolation, use it in the double integral. You may use NIntegrate to evaluate the integral.

POSTED BY: Ta'a Nwa Dombou
Posted 2 years ago

Can I kindly ask you what is the code for RBF? I can't find something good to transform z to f(x,y).

POSTED BY: nahal ghanadi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract