MATLAB Answers

0

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

Asked by Mohamed Elasmar on 2 May 2019
Latest activity Commented on by Mohamed Elasmar on 7 May 2019
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

Unfortunately, the equation of ''diff(p) / diff(phi)'' gives all the results as zeros.
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.
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.

1 Answer

Answer by jahanzaib ahmad on 3 May 2019

matrix=[matrix(:,1), (matrix(:,2:end)/2)]

  1 Comment

Sign in to comment.