Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Using Diff

Subject: Using Diff

From: Dean

Date: 27 Dec, 2010 02:44:05

Message: 1 of 7

I have three positive variables, x, y and z, subject to the constraint x+y+z=1. My understanding is that because of the constraint, the partial derivative of any of the three variables with respect to another is -1, i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1. Does anyone know how to define this system of variables and the constraint in MATLAB so that the partial derivatives are all evaluated as -1?

Below is my unsuccessful attempt:

>> syms x y z positive
>> x+y+z=1;
??? x+y+z=1;
         |
Error: The expression to the left of the equals sign is not a valid target for an
assignment.
 
>> z=1-x-y;
>> diff(z,x)
 
ans =
 
-1
 
>> diff(z,y)
 
ans =
 
-1
 
>> diff(x,z)
 
ans =
 
diff(x, 1 - y - x)
 
>> diff(x,y)
 
ans =
 
0
 
>> diff(y,x)
 
ans =
 
0
 
>> diff(y,z)
 
ans =
 
diff(y, 1 - y - x)

Thanks for your time,
Dean

Subject: Using Diff

From: Walter Roberson

Date: 27 Dec, 2010 03:05:58

Message: 2 of 7

On 26/12/10 8:44 PM, Dean wrote:
> I have three positive variables, x, y and z, subject to the constraint
> x+y+z=1. My understanding is that because of the constraint, the partial
> derivative of any of the three variables with respect to another is -1,
> i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1.

No, that is incorrect. Unless you have other constraints, it would, for
example, be quite valid for x = y and z = 1 - 2*x, which would give
dy/dx = 1 and dz/dx = -2 . The requirement that the variables be
positive does not interfere with this, as all three variables would be
non-negative in the range x = 0 to 1/2

Subject: Using Diff

From: Dean

Date: 27 Dec, 2010 23:45:19

Message: 3 of 7

Walter Roberson <roberson@hushmail.com> wrote in message <qoTRo.3509$z06.701@newsfe08.iad>...
> On 26/12/10 8:44 PM, Dean wrote:
> > I have three positive variables, x, y and z, subject to the constraint
> > x+y+z=1. My understanding is that because of the constraint, the partial
> > derivative of any of the three variables with respect to another is -1,
> > i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1.
>
> No, that is incorrect. Unless you have other constraints, it would, for
> example, be quite valid for x = y and z = 1 - 2*x, which would give
> dy/dx = 1 and dz/dx = -2 . The requirement that the variables be
> positive does not interfere with this, as all three variables would be
> non-negative in the range x = 0 to 1/2

Walter,

Thankyou for your reply. However, I disagree with what you are saying. The set of (x,y,z) subject to the constraints x,y,z>=0 and x+y+z=1 fully describes a 2-D bounded plane, triangular in shape, in R^3. It is bounded by the lines x+y=1, x+z=1, and y+z=1. Naturally, there are certain points on that plane that satisfy the conditions x=y and z=1-2x. These points represent the intersection of the plane described above with the plane x=y, all z in R. There are also certain points on the plane which represent the intersection with y=2x, all z in R, or y=257x, all z in R. This doesn't then mean that dy/dx=257 at these points on the plane.

As an analogy, take the function y=x^2. It intersects with y=x at x=0 and 1. Just because it is valid to say y=x at these points, it does not follow that dy/dx=1, rather than dy/dx=2x. It is the function y=x^2, not the extra condition y=x, that specifies the value of the derivative. Likewise, in my case it is the plane constraint x+y+z=1, and not arbitrary extra conditions like x=y, that specify the partial derivatives on the plane.

Dean

Subject: Using Diff

From: Mark Shore

Date: 28 Dec, 2010 00:20:24

Message: 4 of 7

"Dean " <dchesterfield@hotmail.com> wrote in message <ifb8ef$s22$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <qoTRo.3509$z06.701@newsfe08.iad>...
> > On 26/12/10 8:44 PM, Dean wrote:
> > > I have three positive variables, x, y and z, subject to the constraint
> > > x+y+z=1. My understanding is that because of the constraint, the partial
> > > derivative of any of the three variables with respect to another is -1,
> > > i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1.
> >
> > No, that is incorrect. Unless you have other constraints, it would, for
> > example, be quite valid for x = y and z = 1 - 2*x, which would give
> > dy/dx = 1 and dz/dx = -2 . The requirement that the variables be
> > positive does not interfere with this, as all three variables would be
> > non-negative in the range x = 0 to 1/2
>
> Walter,
>
> Thankyou for your reply. However, I disagree with what you are saying. The set of (x,y,z) subject to the constraints x,y,z>=0 and x+y+z=1 fully describes a 2-D bounded plane, triangular in shape, in R^3. It is bounded by the lines x+y=1, x+z=1, and y+z=1. Naturally, there are certain points on that plane that satisfy the conditions x=y and z=1-2x. These points represent the intersection of the plane described above with the plane x=y, all z in R. There are also certain points on the plane which represent the intersection with y=2x, all z in R, or y=257x, all z in R. This doesn't then mean that dy/dx=257 at these points on the plane.
>
> As an analogy, take the function y=x^2. It intersects with y=x at x=0 and 1. Just because it is valid to say y=x at these points, it does not follow that dy/dx=1, rather than dy/dx=2x. It is the function y=x^2, not the extra condition y=x, that specifies the value of the derivative. Likewise, in my case it is the plane constraint x+y+z=1, and not arbitrary extra conditions like x=y, that specify the partial derivatives on the plane.
>
> Dean

Well, you've added additional constraints to your first post by stating that you are looking at continuous x,y,z in the plane x + y + z = 1, haven't you? The initial post could well have been describing a single point x = 1, y = 0, z = 0 with all partial derivatives undefined.

Subject: Using Diff

From: Walter Roberson

Date: 28 Dec, 2010 01:45:32

Message: 5 of 7

On 27/12/10 5:45 PM, Dean wrote:
> > I have three positive variables, x, y and z, subject to the constraint
> > x+y+z=1. My understanding is that because of the constraint, the partial
> > derivative of any of the three variables with respect to another is -1,
> > i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1.

Dean, you said that you have three positive variables, but you did not
say explicitly that they are independent variables. Without that
knowledge that they are independent, the partial derivatives are not equal.

d(1-y-z)/dy = 0 - 1 dy/dy - 1 * dz/dy = -1 - dz/dy
which is not the same as -1 .

Absent the information that the variables are independent, we are
allowed to choose (e.g.) x = y.

 > The set of (x,y,z) subject to the constraints x,y,z>=0 and x+y+z=1
 > fully describes a 2-D bounded plane, triangular in shape, in R3.

Indeed, but that is not exactly the same conditions as you asked about.

Anyhow, to answer at least in part:

diff(solve('x+y+z=1',x),y)


I am not sure there is any way to construct a system of equations with
the properties you desire.

Subject: Using Diff

From: Dean

Date: 28 Dec, 2010 07:23:05

Message: 6 of 7

Walter Roberson <roberson@hushmail.com> wrote in message <1jbSo.13458$2G7.2261@newsfe13.iad>...
> On 27/12/10 5:45 PM, Dean wrote:
> > > I have three positive variables, x, y and z, subject to the constraint
> > > x+y+z=1. My understanding is that because of the constraint, the partial
> > > derivative of any of the three variables with respect to another is -1,
> > > i.e. dy/dx=dy/dz=dx/dy=dx/dz=dz/dy=dz/dx=-1.
>
> Dean, you said that you have three positive variables, but you did not
> say explicitly that they are independent variables. Without that
> knowledge that they are independent, the partial derivatives are not equal.
>
> d(1-y-z)/dy = 0 - 1 dy/dy - 1 * dz/dy = -1 - dz/dy
> which is not the same as -1 .
>
> Absent the information that the variables are independent, we are
> allowed to choose (e.g.) x = y.
>
> > The set of (x,y,z) subject to the constraints x,y,z>=0 and x+y+z=1
> > fully describes a 2-D bounded plane, triangular in shape, in R3.
>
> Indeed, but that is not exactly the same conditions as you asked about.
>
> Anyhow, to answer at least in part:
>
> diff(solve('x+y+z=1',x),y)
>
>
> I am not sure there is any way to construct a system of equations with
> the properties you desire.

Walter,

Regarding the independence of the variables, there is no direct relation between the variables other than the constraint x+y+z=1. Does this mean the variables are independent, or does x+y+z=1 imply dependence?

I am a chemical engineer and the x, y and z in this problem refer to mole fractions. The reason I need to know the partial derivatives, is that I am dealing with a function F(x,y,z). I have to work out Grad(F), that is the vector (dF/dx, dF/dy, dF/dz). To evaluate say dF/dx requires evaluating the partial derivative of terms that contain y or z with respect to x. And it's here that I am stuck.

I was thinking that in performing partial differentiation, you differentiate wrt the chosen variable, treating other variables as constants. So to evaluate the partial derivative of z wrt x for example, dz/dx=d/dx(1-x-y)=0-1-0=-1. As you say, this is only true if y is independent of x. What also makes me think -1 is that when I picture the plane defined by x,y,z>=0, x+y+z=1, and take a slice orthogonal to any of the x, y or z axes, I get a line with gradient -1.

Dean

Subject: Using Diff

From: Walter Roberson

Date: 28 Dec, 2010 21:14:11

Message: 7 of 7

On 28/12/10 1:23 AM, Dean wrote:

> Regarding the independence of the variables, there is no direct relation
> between the variables other than the constraint x+y+z=1. Does this mean
> the variables are independent, or does x+y+z=1 imply dependence?
>
> I am a chemical engineer and the x, y and z in this problem refer to
> mole fractions. The reason I need to know the partial derivatives, is
> that I am dealing with a function F(x,y,z). I have to work out Grad(F),
> that is the vector (dF/dx, dF/dy, dF/dz). To evaluate say dF/dx requires
> evaluating the partial derivative of terms that contain y or z with
> respect to x. And it's here that I am stuck.

Dean, I'm still not sure about this. Your statement that there is no
relationship between the variables other than the constraint would imply
that the variables are independent, as an change in one of them could
satisfy the constraints by way of a change in either or both of the
others with no particular "direction" of change implied.

On the other hand, you are talking about mole fractions. I don't think
I've thought about mole fractions since first year university 30 years
ago. Based upon the somewhat small (mole?) fraction of that knowledge
that I have retained, it does not sound correct to me that the mole
fractions are independent -- or at least that they are not *necessarily*
independent. Not unless you are under an unstated constraint that the
whatever is going on in the system has the effect of adding or removing
substances from the system without affecting the other substances -- but
your mention of chemical gradients suggests to me that instead you are
dealing with systems in which substances get transformed rather than
added or removed.

Consider a simple case in the case which substances get transformed:
water is balanced between H2O, H2, and O2, and the balance point is
measured with the classical pH. As H2O disassociates, the mole fraction
of it decreases, and the mole fraction of the H2 and O2 are driven
upwards in tandem, H2 twice as quickly as O2; likewise with
recombination, the rate of decrease of H2 and O2 is linked and opposite
the increase in H2O.

Hence, just saying that it is a "mole fraction" is not enough to imply
independence of the values: you need to know the properties of the
system. I would point out, though, that if substances do not get
transformed in to each other, but that the system can add one of the
substances, then in order to maintain the balance, the mole fractions of
the other two substances would _both_ have to decrease: without
transformation of substances, if one of the substances were added, the
system could not spontaneously respond by decreasing the mole fraction
of a second substance and increasing the mole fraction of a third.


Mind you, transformation mathematics I used above did imply a movement
of atoms from one substance to another, and does not take in to account
that there can be transformations in which the conformation changes
while still retaining the same atoms. The response to such a system to
the addition of more of one substance would not usually be chaotic: the
direction of reaction would usually be predictable. The direction of
reaction could, though, depend upon an environmental condition such as
temperature... though if it did, that would not mean that the variables
were independent, just that the dependence included another factor.


In summary, I _suspect_ that in your system, the variables are *not*
independent.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us