# 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 件のコメント

Mohamed Elasmar 2019 年 5 月 5 日
Unfortunately, the equation of ''diff(p) / diff(phi)'' gives all the results as zeros.
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 件のコメント

jahanzaib ahmad 2019 年 5 月 3 日
2 is dphi

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by