Path: news.mathworks.com!not-for-mail From: "Dean " <dchesterfield@hotmail.com> Newsgroups: comp.soft-sys.matlab Subject: Partial differentiation Date: Thu, 16 Dec 2010 01:52:07 +0000 (UTC) Organization: Univ of New South Wales Lines: 53 Message-ID: <iebrc7$17f$1@fred.mathworks.com> Reply-To: "Dean " <dchesterfield@hotmail.com> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1292464327 1263 172.30.248.38 (16 Dec 2010 01:52:07 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Thu, 16 Dec 2010 01:52:07 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2581889 Xref: news.mathworks.com comp.soft-sys.matlab:695922 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 3-element 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=1-x2-x3. 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