필터 지우기
필터 지우기

Differentiate and store results in matrix

조회 수: 4 (최근 30일)
Benjamin
Benjamin 2018년 11월 5일
편집: Star Strider 2018년 11월 5일
I have two matrices. The first matrix is Density and it 311x1. The second matrix is Temperature and it is 311x21. The column in density matrix corresponds to each distinct column in temperature matrix.
So if I want to plot the first line I could just do:
plot(Density, Temperature(:,1))
and second line would just be:
plot(Density, Temperature(:,2))
How can I create a new matrix that takes the derivative of each temperature line (isotherm) with respect to density, and put this in a new matrix, such as diffTemperature?

채택된 답변

Star Strider
Star Strider 2018년 11월 5일
Try this:
Density = (0:310)'; % Create Data
Temperature = sin((0:310)'*(0:20)*2*pi/20); % Create Data
dTdD = gradient(Temperature, mean(diff(Density))); % Equal Spacing
dTdD = gradient(Temperature) ./ gradient(Density); % Unequal Spacing
figure
plot(Density, Temperature(:,5))
hold on
plot(Density, dTdD(:,5))
hold off
grid
title('Example')
legend('Temperature', 'Derivative')
xlim([0 30])
  댓글 수: 8
Benjamin
Benjamin 2018년 11월 5일
편집: Benjamin 2018년 11월 5일
Wow, hey that works! What would it be to take 2nd derivative?
[~,ddPddD] = gradient(dPdD, mean(diff(density)));
Star Strider
Star Strider 2018년 11월 5일
편집: Star Strider 2018년 11월 5일
Great!
Yes. That will work for equally-spaced data.
EDIT An alternative could also be the del2 (link) function on ‘Temperature’ (or any other dependent variable), not the derivative, (although you may need to multiply the result by 4). The syntax is essentially the same.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by