Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 5 May 2019
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
Mohamed Elasmar on 7 May 2019
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!

Sign in to comment.

Answers (1)

jahanzaib ahmad
jahanzaib ahmad on 3 May 2019
matrix=[matrix(:,1), (matrix(:,2:end)/2)]

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!