cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Partial Derivative with Matrix

MrichCD
4-Participant

Partial Derivative with Matrix

I tend to do a lot of partial differentiation in my analyses and how I currently do it is to hard code each partial to their own variable. This tends to clutter my analyses, since I deal with rather large multi-variable equations. I tried being slick today by defining a 1xn matrix (where n is the total number of variables and each element contains the variable names that I need to do partial derivatives on) and performing the partial derivatives on that matrix and vectorizing it. Mathcad doesn't flag an error, but what it's calculating isn't correct. I believe it's trying to do the differentiation on the value of the variable rather than seeing it as a variable by itself, because it always calculates the result as 0. Does anyone know how I can get mathcad to see these as variables or know I better way of going about this? I've attached an example of what I am attempting if it isn't clear in my writing. 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:MrichCD)

I guess this is an example of what you're trying to achieve:

LM_20190401_PartialDiffs.png

This was done in Mathcad 11. As far as I can tell, this same is NOT possible in any other version of Mathcad above or below 11, nor in any version of Prime.

 

Luc

View solution in original post

10 REPLIES 10
LucMeekes
23-Emerald III
(To:MrichCD)

I see a few problems, solving of which - may - help:

1.

You have (x3)^3 in your matrix X, guess that's not what you intended...

2.

X is a matrix (1 row, 4 columns), Vectorization may only work with a vector (4 rows, 1 column). It just might help to transpose X...

3.

Try symbolic evaluation, instead of numeric, and make sure x1 through x4 are not defined when differentiating. Don't define them in the first place, and/or make Partial a function of x1 through x4.

 

This is done in Mathcad 11:

LM_20190401_PartialDiff.png

The last two items:

f is differentiated to X (which as a symbol, is NOT a parameter of f), so the partial derivative is 0.

 

Success!

Luc

 

 

MrichCD
4-Participant
(To:LucMeekes)

1. Correct, that was just a typo

2. I use vectorization on 1xn matrices all the time, it should just go through element by element. Either way, I have tried just transposing it and it still returns 0.

3. I am not following how I'd be able to do that? How would I set up a symbolic expression without defining my variables when I intend to use a matrix for those variables? Also, setting Partials as a function of the variables just flags an error. 

LucMeekes
23-Emerald III
(To:MrichCD)

Why would that flag an error (unless you're using an equals, that is, a numeric evaluation, at the end of the definition)?

My opinion: While it is supported, I think it is bad practice to append a numerical evaluation to a definition. We've had more users complaining about errors due to this. It results in errors because the numeric evaluator cannot handle undefined variables. (Important note: the symbolic processor and evaluator has no problems with undefined variables) So: Define, then do the numeric evaluation separately.

 

Success!
Luc

 

LucMeekes
23-Emerald III
(To:MrichCD)

I guess this is an example of what you're trying to achieve:

LM_20190401_PartialDiffs.png

This was done in Mathcad 11. As far as I can tell, this same is NOT possible in any other version of Mathcad above or below 11, nor in any version of Prime.

 

Luc

draagekreik
5-Regular Member
(To:MrichCD)


@MrichCD wrote:

I tend to do a lot of partial differentiation in my analyses and how I currently do it is to hard code each partial to their own variable. This tends to clutter my analyses, since I deal with rather large multi-variable equations. I tried being slick today by defining a 1xn matrix (where n is the total number of variables and each element contains the variable names that I need to do partial derivatives on) and performing the partial derivatives on that matrix and vectorizing it. Mathcad doesn't flag an error, but what it's calculating isn't correct. I believe it's trying to do the differentiation on the value of the variable rather than seeing it as a variable by itself, because it always calculates the result as 0. Does anyone know how I can get mathcad to see these as variables or know I better way of going about this? I've attached an example of what I am attempting if it isn't clear in my writing. 


I wanted to try out your file and see if I could help out but I'm using MathCAD 15 and I cannot open mcdx files.  I think that it would be best for you to write some of your own vectorization code.  I did so for the modular arithmetic operator because the MathCAD programming team at PTC saw fit to ruin the vectorize operator in such a way that MathCAD docs created previously (in MathCAD 14 or earlier) now are erroneous when run using MathCAD 15.  I will give it some thought, but it would help if you can export your file to a MathCAD 15 doc and upload that as well.  The programming I'm, thinking of should not require that we use the same versions.  Another way you can help me help you is to upload a screenshot or a PDF printout of your MathCAD Prime doc.  

LucMeekes
23-Emerald III
(To:draagekreik)

There is NO possibility to save a (.mcdx) Prime file in any (real) Mathcad (.mcd or .xmcd) format.

Actually there is also no means to save a Prime 5 file into Prime 4 (or less) format.

But you can install the free Prime Express (version 5 if you have a 64 bit OS,  or any older version if you have a 32-bit OS) and open a Prime file on this forum. As a first time user/evaluator you can get the first 30 days of full functionality, after which the really cool features are gone.

 

Success!
Luc

draagekreik
5-Regular Member
(To:LucMeekes)


@LucMeekes wrote:

There is NO possibility to save a (.mcdx) Prime file in any (real) Mathcad (.mcd or .xmcd) format.

Actually there is no means to save a Prime 5 file into Prime 4 (or less) format.

But you can install the free Prime Express (version 5 if you have a 64 bit OS,  or any older version if you have a 32-bit OS) and open a Prime file on this forum. As a first time user/evaluator you can get the first 30 days of full functionality, after which the really cool features are gone.

 

Success!
Luc


I don't want Prime or any of its variations.  It is too different from the versions of MathCAD I use, and I don't want more clutter on my computers.  I don't plan to use prime, I just want to see his doc, so a PDF will be preferred.  

LucMeekes
23-Emerald III
(To:draagekreik)

Here you go:

LM_20190403_PartDiff.png

Success!

Luc

draagekreik
5-Regular Member
(To:LucMeekes)

What is one "cool feature" of prime that I am missing by using MathCAD 15 or earlier?

 

 

 

 

 


@LucMeekes wrote:

There is NO possibility to save a (.mcdx) Prime file in any (real) Mathcad (.mcd or .xmcd) format.

Actually there is also no means to save a Prime 5 file into Prime 4 (or less) format.

But you can install the free Prime Express (version 5 if you have a 64 bit OS,  or any older version if you have a 32-bit OS) and open a Prime file on this forum. As a first time user/evaluator you can get the first 30 days of full functionality, after which the really cool features are gone.

 

Success!
Luc


 

LucMeekes
23-Emerald III
(To:draagekreik)

Mixed units in vectors and arrays. That's a feature of Prime, not supported by Mathcad (15 and below).

But that wasn't one of the 'cool features' that I was referring to.

If you install Prime without abought license you can get 30 days of full (licensed) functioning.

After that you lose the 'cool features':

symbolics, programming, solve blocks, referenced worksheets, and a lot of functions like:

polyroots, rkfixed, statistic distribution functions and a lot more, including mean, Re and Im.

With respect to that list of functions, some mending is possible, see https://community.ptc.com/t5/PTC-Mathcad/Prime-Express-A-joke/m-p/604216#M185378.

 

Luc

Announcements

Top Tags