topic Derivative of a function with vector arguments in PTC Mathcad
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643390#M188487
<P>I'm using Mathcad Prime 5.0.</P>
<P> </P>
<P>I have the following function defined.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_0-1578500141838.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22508i23D4360776A546EF/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_0-1578500141838.png" alt="JonWarriner_0-1578500141838.png" /></span></P>
<P>The intent if for this function to be very generic and allow any number of inputs. Therefore, Vin and Rin are vectors of the same length. Here's how those are setup.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_1-1578500257064.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22509iB57294ABC37FE0AF/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_1-1578500257064.png" alt="JonWarriner_1-1578500257064.png" /></span></P>
<P>The function itself works fine. </P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_2-1578500295197.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22510i620C19A149437DED/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_2-1578500295197.png" alt="JonWarriner_2-1578500295197.png" /></span></P>
<P>Now, I need to take the derivative of that function with respect to the individual components of Rin. The intent is to estimate how much effect the variation of each individual component has on the overall output. Ultimately the expression and number of parameters will be bigger than what I've shown here. I just scaled everything back to a simpler example to illustrate the actual problem. I was hoping the derivative with respect to Rin would give me a vector of the numerically evaluated derivative with respect to each individual resistance. Instead it tells me everything has to be scalar.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_4-1578501004601.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22512i126A51F481E66458/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_4-1578501004601.png" alt="JonWarriner_4-1578501004601.png" /></span></P>
<P>I found some old posts similar to this dating back to 2004 and 2005. They basically said this isn't possible. I was hoping something may have changed in 14 to 15 years. </P>
<P> </P>
<P>Thanks,</P>
<P>Jon</P>Wed, 08 Jan 2020 16:31:49 GMTJonWarriner2020-01-08T16:31:49ZDerivative of a function with vector arguments
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643390#M188487
<P>I'm using Mathcad Prime 5.0.</P>
<P> </P>
<P>I have the following function defined.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_0-1578500141838.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22508i23D4360776A546EF/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_0-1578500141838.png" alt="JonWarriner_0-1578500141838.png" /></span></P>
<P>The intent if for this function to be very generic and allow any number of inputs. Therefore, Vin and Rin are vectors of the same length. Here's how those are setup.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_1-1578500257064.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22509iB57294ABC37FE0AF/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_1-1578500257064.png" alt="JonWarriner_1-1578500257064.png" /></span></P>
<P>The function itself works fine. </P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_2-1578500295197.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22510i620C19A149437DED/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_2-1578500295197.png" alt="JonWarriner_2-1578500295197.png" /></span></P>
<P>Now, I need to take the derivative of that function with respect to the individual components of Rin. The intent is to estimate how much effect the variation of each individual component has on the overall output. Ultimately the expression and number of parameters will be bigger than what I've shown here. I just scaled everything back to a simpler example to illustrate the actual problem. I was hoping the derivative with respect to Rin would give me a vector of the numerically evaluated derivative with respect to each individual resistance. Instead it tells me everything has to be scalar.</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_4-1578501004601.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22512i126A51F481E66458/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_4-1578501004601.png" alt="JonWarriner_4-1578501004601.png" /></span></P>
<P>I found some old posts similar to this dating back to 2004 and 2005. They basically said this isn't possible. I was hoping something may have changed in 14 to 15 years. </P>
<P> </P>
<P>Thanks,</P>
<P>Jon</P>Wed, 08 Jan 2020 16:31:49 GMThttps://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643390#M188487JonWarriner2020-01-08T16:31:49ZRe: Derivative of a function with vector arguments
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643393#M188488
<BLOCKQUOTE><HR />was hoping something may have changed in 14 to 15 years. <BR /><HR /></BLOCKQUOTE>
<P>Unfortunately not (apart from the development of Prime which actually is a big step backwards).</P>
<P>You will have to find a workaround which sure is not as generic as you'd like it to be <span class="lia-unicode-emoji" title=":disappointed_face:">ðŸ˜ž</span></P>Wed, 08 Jan 2020 17:04:38 GMThttps://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643393#M188488Werner_E2020-01-08T17:04:38ZRe: Derivative of a function with vector arguments
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643408#M188489
<P>You can find your work-around on the internet.</P>Wed, 08 Jan 2020 18:47:56 GMThttps://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643408#M188489Fred_Kohlhepp2020-01-08T18:47:56ZRe: Derivative of a function with vector arguments
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643427#M188494
<P>Fred,</P>
<P> </P>
<P>Thanks! Your approach didn't quite give me what I wanted but it got me thinking.</P>
<P>What I was trying to get was an approximate, linearized effect of each component on the output. Your solution gave me the sum of the derivatives for each component. </P>
<P> </P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_0-1578515538174.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22520i16860D91007281E5/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_0-1578515538174.png" alt="JonWarriner_0-1578515538174.png" /></span></P>
<P>But, your approach got me thinking that I was being too lazy in trying to let Mathcad do all of the work. The partial derivative with respect to each resistor in my input vector just boils down to this:</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_1-1578515673374.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22521i642179A694D0BD3A/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_1-1578515673374.png" alt="JonWarriner_1-1578515673374.png" /></span></P>
<P>Then, I can just pass my input vector to that function and get my individual results:</P>
<P><span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonWarriner_2-1578515745911.png" style="width: 400px;"><img src="https://community.ptc.com/t5/image/serverpage/image-id/22522i821AF9C4195790E3/image-size/medium?v=v2&px=400" role="button" title="JonWarriner_2-1578515745911.png" alt="JonWarriner_2-1578515745911.png" /></span></P>
<P>Thanks,</P>
<P>Jon</P>Wed, 08 Jan 2020 20:39:15 GMThttps://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643427#M188494JonWarriner2020-01-08T20:39:15ZRe: Derivative of a function with vector arguments
https://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643440#M188497
<P>Mathcad is a great tool, but not the best one you have. NASA went to the moon with pencils and slide rules!</P>
<P> </P>
<P>Glad you got to your solution.</P>
<P> </P>
<P>BTW, Version 15 will allow you to let partial derivatives show as partials (greek <FONT face="symbol">d</FONT>). It also has a gradient function (cntrl-shift-G) that would allow partial derivatives of a function of several variables.</P>Wed, 08 Jan 2020 22:49:05 GMThttps://community.ptc.com/t5/PTC-Mathcad/Derivative-of-a-function-with-vector-arguments/m-p/643440#M188497Fred_Kohlhepp2020-01-08T22:49:05Z