# Substituting by a matrix in an equation and getting a new matrix

조회 수: 1 (최근 30일)
Mohamed Elasmar 2019년 5월 2일
댓글: Mohamed Elasmar 2019년 5월 7일
I have an equation for calculating the pressure gradient, which is and I have the following matrix where the first column is the values of phi and the other columns are the pressure cases which I want to calculate the pressure gradient for each of them.
(Note that: i in the equation refers to the position of the value in the column).
phi p1 p2 p3 p4 p5 p6 p7 p8 p9
-140.5000 1.3386 1.6004 2.4960 1.5004 2.0371 2.9061 1.5800 2.1815 3.1080
-140.0000 1.3424 1.6040 2.5028 1.5044 2.0431 2.9150 1.5848 2.1876 3.1167
-139.5000 1.3461 1.6076 2.5085 1.5085 2.0492 2.9235 1.5899 2.1941 3.1265
-139.0000 1.3495 1.6109 2.5143 1.5127 2.0553 2.9317 1.5948 2.2005 3.1366
-138.5000 1.3536 1.6147 2.5206 1.5171 2.0618 2.9395 1.5999 2.2073 3.1459
How can I substitute by the values of phi and pressure in the equation and get the following matrix?
phi p1/dphi dp2/dphi dp3/dphi dp4/dphi dp5/dphi dp6/dphi dp7/dphi dp8/dphi dp9/dphi
##### 댓글 수: 5이전 댓글 3개 표시이전 댓글 3개 숨기기
Walter Roberson 2019년 5월 5일
I did not say diff(p) / diff(phi) I said diff(p) ./ diff(phi)
diff(p) for vector p is defined as p(2:end) - p(1:end-1) which is your numerator. diff(phi) = phi(2:end) - phi(1:end-1) is your denominator. ./ is element-by-element division.
Mohamed Elasmar 2019년 5월 7일
You are correct! I have already used the formula with (./) and it has successfully run showing the required results.
Thank you very much for your help!

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

### 답변 (1개)

jahanzaib ahmad 2019년 5월 3일
matrix=[matrix(:,1), (matrix(:,2:end)/2)]
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
jahanzaib ahmad 2019년 5월 3일
2 is dphi

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

### 카테고리

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

### Community Treasure Hunt

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

Start Hunting!

Translated by