필터 지우기
필터 지우기

Why du/dx obtained from excel and Matlab gives different results?

조회 수: 2 (최근 30일)
Raushan
Raushan 2023년 1월 11일
댓글: Raushan 2023년 1월 12일
Hi
I have csv file with some columns and I want to find the du/dx from two column named as u and x. I did it in excell as well as matlab but both the results are different. Can anyone please help to know why they are diffrent? Am I doing any mistake while calciulating the derivative in matlab. I want to do this for all the csv files but I wanted to varify first for one file. Here is my code that I used in matlab and the csv file named as 0001_derivative in which I have obtained du/dx i.e. (u2-u1)/(x2-x1)and named as "s"
Folder='G:\testcodeforcsvcolumn'
Data = readtable('0001.csv');
U = Data.u;
X = Data.x;
dudx = gradient(U)./gradient(X);
Thank you very much for helping me to learn.
  댓글 수: 4
Torsten
Torsten 2023년 1월 12일
It's nonsense to calculate dudx this way since your X data are not in increasing order.
You must first order X and then arrange U according to the X-ordering.
Raushan
Raushan 2023년 1월 12일
Thanks for the suggestion. You are right we can arrange them either in increasing or decreasing order, but that will be manipulation with the data. We expect data to vary like this. Code is working for 1 file but not for all 5 files. Can you please help me to implement a for loop for 5 files, so that I will have 5 different dudx, I am trying but getting dimension related error.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2023년 1월 11일
If the X grid is equidistant,
dudx = gradient(U,X(2)-X(1))
  댓글 수: 2
Raushan
Raushan 2023년 1월 11일
The difference is 5 between the x values but us not in increasing or decreasing oredr. Sometimes it is in increasing and some times it is in decreasing order.
Raushan
Raushan 2023년 1월 11일
I tried this but still the same value as before. Its not matching with ''s'' column of 0001_derivative.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by