MATLAB Newsgroup
Hi,
I am struggling a bit with what I guess should be a simple problem. I have a function F(x), R^3>R, where x is a 3element symbolic vector [x1 x2 x3]. I need to obtain the gradient vector of F with respect to x, which involves calculating the partial derivative of F with respect to each of x1, x2, and x3.
Now x1,x2 and x3 represent real positive variables, and they are subject to the constraint x1+x2+x3=1. So I believe that the partial derivative of xi wrt xj, where j is not equal to i, should be 1. Unfortunately I don't know how to specify this in MATLAB. I find I must write the constraint as x1=1x2x3. I can then obtain diff(x1,x2)=diff(x1,x3)=1, as I hoped. However, MATLAB does not seem to evaluate any of the other partial derivatives, e.g. diff(x2,x1) = diff(x2,1  x3  x2), NOT 1. I don't know how to specify in MATLAB that all such partial derivates equal 1. The following is a few lines of what I've tried in MATLAB and the errors encountered. Any assistance would be greatly appreciated.
>> syms x1 x2 x3 real
>> x1 + x2 + x3 =1
??? x1 + x2 + x3 =1

Error: The expression to the left of the equals sign is not a valid target for an
assignment.
>> x1 = 1  (x2 + x3)
x1 =
1  x3  x2
>> diff(x2,x1)
ans =
diff(x2, 1  x3  x2)
>> diff(x1,x2)
ans =
1
>> diff(x1,x3)
ans =
1
>> x2=1(x1+x3)
x2 =
x2
>> diff(x2,x1)
ans =
diff(x2, 1  x3  x2)
Thanks for your time.
Dean
"Dean " <dchesterfield@hotmail.com> wrote in message <iebrc7$17f$1@fred.mathworks.com>...
> Hi,
>
> I am struggling a bit with what I guess should be a simple problem. I have a function F(x), R^3>R, where x is a 3element symbolic vector [x1 x2 x3]. I need to obtain the gradient vector of F with respect to x, which involves calculating the partial derivative of F with respect to each of x1, x2, and x3.
>
> Now x1,x2 and x3 represent real positive variables, and they are subject to the constraint x1+x2+x3=1. So I believe that the partial derivative of xi wrt xj, where j is not equal to i, should be 1. Unfortunately I don't know how to specify this in MATLAB. I find I must write the constraint as x1=1x2x3. I can then obtain diff(x1,x2)=diff(x1,x3)=1, as I hoped. However, MATLAB does not seem to evaluate any of the other partial derivatives, e.g. diff(x2,x1) = diff(x2,1  x3  x2), NOT 1. I don't know how to specify in MATLAB that all such partial derivates equal 1. The following is a few lines of what I've tried in MATLAB and the errors encountered. Any assistance would be greatly appreciated.
> ......
           
You have written "F(x), R^3>R" which I was taught to interpret as "F maps (all of) R^3 space into R". Yet you have also said that the coordinates are restricted by x1+x2+x3=1 and x1>0, x2>0, x3>0. As it stands those two statements do not make good mathematical sense together. If you truly have a mapping from all of R^3 into R, then the three partial derivatives have a meaning without reference to the above constraints. If F only maps a subset plane of R^3 into R satisfying the constraints, then the three independent partial derivatives with respect to x1, x2, and x3 have no joint meaning.
The plane is a twodimensional space and can have two independent variables defining position in that plane. It is valid to take partial derivatives with respect to such a pair of variables. For example you could let x1 and x2 be the two independent variables with the understanding that x3 is always equal to 1x1x2. However the two partial derivatives are by no means the same as those of the corresponding partials for the whole R^3 space. For example the gradient of F using two such variables would always point parallel to the plane, whereas the gradient of F in the full R^3 space in general has no such restriction.
I think you need to straighten out these concepts in your own mind before any useful help can be forthcoming from this group. Do you actually have a mapping of the entire R^3 into R or not? If you do, what two variables would you choose to represent position in the R^2 plane? Do they give distances between pairs of points equal to the corresponding distances in the R^3 x1x2x3 space? (The above example of using the x1 and x2 pair would not satisfy this last.)
Roger Stafford
"Dean " <dchesterfield@hotmail.com> wrote in message <iebrc7$17f$1@fred.mathworks.com>...
> I am struggling a bit with what I guess should be a simple problem. I have a function F(x), R^3>R, where x is a 3element symbolic vector [x1 x2 x3]. I need to obtain the gradient vector of F with respect to x, which involves calculating the partial derivative of F with respect to each of x1, x2, and x3.
>
> Now x1,x2 and x3 represent real positive variables, and they are subject to the constraint x1+x2+x3=1. ........
           
To expand upon what I wrote yesterday, suppose that your F is defined over threedimensional space but that you are interested in some kind of gradient defined on the plane x+y+z=1. (I switched to x, y, and z for brevity instead of your x1, x2, x3.)
It is advantageous to define coordinates u and v in this plane that preserve the Euclidean metric. That is, if the points (u1,v1) and (u2,v2) in plane coordinates correspond respectively to (x1,y1,z1) and (x2,y2,z2) in the x,y,z coordinate system, then
((u2u1)^2+(v2v1)^2)^(1/2) = ((x2x1)^2+(y2y1)^2+(z2z1)^2)^(1/2)
always holds.
One definition of u and v coordinates that satisfies this equality is
x = 1/3+1/sqrt(6)*2*u
y = 1/31/sqrt(6)*(usqrt(3)*v)
z = 1/31/sqrt(6)*(u+sqrt(3)*v)
It is easy to check that x+y+z=1 is identically true for all u and v, so this is a valid parametric representation of points on your plane. A little more work can show that the Euclidean metric is preserved.
Taking advantage of the identities
dF/du = dF/dx*dx/du + dF/dy*dy/du + dF/dz*dz/du
dF/dv = dF/dx*dx/dv + dF/dy*dy/dv + dF/dz*dz/dv
you can show that the 2D gradient [dF/du,dF/dv] simply amounts to the orthogonal projection of the 3D gradient [dF/dx,dF/dy,dF/dz] onto the plane.
In the above, the origin of the u, v coordinates was located at x,y,z coordinates (1/3,1/3,1/3). This origin could actually have been placed anywhere on the plane. The u and v axes could also have been rotated around the plane normal by any angle provided they remain mutually orthogonal and you would still have a coordinate system that would relate the two different gradients in the above relation: the u,v 2D gradient being the projection of the x,y,z 3D gradient onto the plane.
With plane coordinates that do not satisfy this metricpreserving condition, the relationship between the 2D (plane) and the 3D gradients would be more complicated.
I hope this serves to clarify the situation of the gradient concept when defined in terms of plane surface coordinates.
Roger Stafford
Thanks for your feedback Roger.
You are correct, I did make an error in stating "F(x), R^3>R", as F does not map all of R^3 to R, just the subset of (x,y,z) that satisfies the constraints x+y+z=1 and x>=0, y>=0, z>=0. The x, y and z in my case represent mole fractions in a liquid, hence the constraints.
I understand that because of the constraints, the domain of valid coordinates is a twodimensional plane, and therefore only two independent variables are required to define position in the plane. In my case, I just use x and y to define position, and when in future I work out Grad(F), I will just use the first two elements, ie. 2D gradient given by (dF/dx,dF/dy).
My main problem lay in the actual evaluation of dF/dx and dF/dy. F is a function in x, y and z. So in the process of evaluating the partial derivative of F with respect to x, say, I come across a term in F which contains y or z, and am faced with the question of "What does dy/dx and dz/dx equal?". Do they equal 0, or because of the constraint x+y+z=1, do they equal 1?
I appreciate the time you have taken to reply to my post.
Dean
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <iedsbg$j7r$1@fred.mathworks.com>...
> "Dean " <dchesterfield@hotmail.com> wrote in message <iebrc7$17f$1@fred.mathworks.com>...
> > I am struggling a bit with what I guess should be a simple problem. I have a function F(x), R^3>R, where x is a 3element symbolic vector [x1 x2 x3]. I need to obtain the gradient vector of F with respect to x, which involves calculating the partial derivative of F with respect to each of x1, x2, and x3.
> >
> > Now x1,x2 and x3 represent real positive variables, and they are subject to the constraint x1+x2+x3=1. ........
>            
> To expand upon what I wrote yesterday, suppose that your F is defined over threedimensional space but that you are interested in some kind of gradient defined on the plane x+y+z=1. (I switched to x, y, and z for brevity instead of your x1, x2, x3.)
>
> It is advantageous to define coordinates u and v in this plane that preserve the Euclidean metric. That is, if the points (u1,v1) and (u2,v2) in plane coordinates correspond respectively to (x1,y1,z1) and (x2,y2,z2) in the x,y,z coordinate system, then
>
> ((u2u1)^2+(v2v1)^2)^(1/2) = ((x2x1)^2+(y2y1)^2+(z2z1)^2)^(1/2)
>
> always holds.
>
> One definition of u and v coordinates that satisfies this equality is
>
> x = 1/3+1/sqrt(6)*2*u
> y = 1/31/sqrt(6)*(usqrt(3)*v)
> z = 1/31/sqrt(6)*(u+sqrt(3)*v)
>
> It is easy to check that x+y+z=1 is identically true for all u and v, so this is a valid parametric representation of points on your plane. A little more work can show that the Euclidean metric is preserved.
>
> Taking advantage of the identities
>
> dF/du = dF/dx*dx/du + dF/dy*dy/du + dF/dz*dz/du
> dF/dv = dF/dx*dx/dv + dF/dy*dy/dv + dF/dz*dz/dv
>
> you can show that the 2D gradient [dF/du,dF/dv] simply amounts to the orthogonal projection of the 3D gradient [dF/dx,dF/dy,dF/dz] onto the plane.
>
> In the above, the origin of the u, v coordinates was located at x,y,z coordinates (1/3,1/3,1/3). This origin could actually have been placed anywhere on the plane. The u and v axes could also have been rotated around the plane normal by any angle provided they remain mutually orthogonal and you would still have a coordinate system that would relate the two different gradients in the above relation: the u,v 2D gradient being the projection of the x,y,z 3D gradient onto the plane.
>
> With plane coordinates that do not satisfy this metricpreserving condition, the relationship between the 2D (plane) and the 3D gradients would be more complicated.
>
> I hope this serves to clarify the situation of the gradient concept when defined in terms of plane surface coordinates.
>
> Roger Stafford
"Dean " <dchesterfield@hotmail.com> wrote in message <ieehar$md1$1@fred.mathworks.com>...
> Thanks for your feedback Roger.
>
> You are correct, I did make an error in stating "F(x), R^3>R", as F does not map all of R^3 to R, just the subset of (x,y,z) that satisfies the constraints x+y+z=1 and x>=0, y>=0, z>=0. The x, y and z in my case represent mole fractions in a liquid, hence the constraints.
>
> I understand that because of the constraints, the domain of valid coordinates is a twodimensional plane, and therefore only two independent variables are required to define position in the plane. In my case, I just use x and y to define position, and when in future I work out Grad(F), I will just use the first two elements, ie. 2D gradient given by (dF/dx,dF/dy).
>
> My main problem lay in the actual evaluation of dF/dx and dF/dy. F is a function in x, y and z. So in the process of evaluating the partial derivative of F with respect to x, say, I come across a term in F which contains y or z, and am faced with the question of "What does dy/dx and dz/dx equal?". Do they equal 0, or because of the constraint x+y+z=1, do they equal 1?
>
> I appreciate the time you have taken to reply to my post.
>
> Dean
          
Your statement that "F is a function in x, y and z" would seem to hint that you might actually have a relationship between F and the quantities x, y, and z that makes sense even when their sum is not restricted to 1. If that is the case, you might be able to make a sensible evaluation of the 3D gradient [dF/dx,dF/dy,dF/dz] which temporarily ignores that constraint.
The main point of what I was trying to tell you earlier is that however you define a planar set of coordinates, if they preserve the metric of the original x,y,z metric, then the 2D gradient using those coordinates will always be just the orthogonal projection of the 3D gradient. In other words you don't need to invent a set of planar coordinates and take their partial derivatives to get such a 2D gradient. Just project the known 3D gradient orthogonally onto the plane. It is a natural way to obtain a 2D gradient from a 3D gradient.
For your constraint this is particularly easy to do. If your 3D gradient is [Fx,Fy,Fz], then the projected 2D gradient is simply
[(2*FxFyFz)/3,(2*FyFzFx)/3,(2*FzFxFy)/3] (1)
It is easy to show that this is a vector parallel to the plane since the sum of its components is zero, which is to say that it is orthogonal to the plane's particular normal direction.
Formula (1) comes from the general formula for orthogonal projection of a vector onto a plane:
Vp = V  dot(N,V)*N (2)
where N is a unit normal vector to the plane, V is the vector to be projected onto the plane, and Vp is its projection within the plane. In your case V = [Fx,Fy,Fz] and N = [1/sqrt(3),1/sqrt(3),1/sqrt(3)] which quickly lead to formula (1).
It seems to me that arbitrarily selecting x and y as your independent variables and restricting z to 1xy might tend to bias the resulting gradient by that particular molar fraction selection. Choosing a different pair of fractions could give different results.
Roger Stafford
You can think of your watch list as threads that you have bookmarked.
You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.
To add items to your watch list, click the "add to watch list" link at the bottom of any page.
To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.
You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.
To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.
To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.
No tags are associated with this thread.
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.
Got questions?
Get answers.
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test
Learn moreDiscover what MATLAB ^{®} can do for your career.
Opportunities for recent engineering grads.
Apply TodayThe newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.
Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.
Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using openstandard protocols. No single entity “owns” the newsgroups.
There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.softsys.matlab newsgroup.
MATLAB Central
You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.
Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.
One Account
Your MATLAB Central account is tied to your MathWorks Account for easy access.
Use the Email Address of Your Choice
The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.
Spam Control
Most newsgroup spam is filtered out by the MATLAB Central Newsreader.
Tagging
Messages can be tagged with a relevant label by any signedin user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.
Watch lists
Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.