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

Replacing symbolic variables and derivatives with other variables

ptc-5748870
1-Visitor

Replacing symbolic variables and derivatives with other variables

Hi all,

I apologise if there is an obvious place I can find the answer to this, but I've googled and googled and come up empty.

I have a vector, x, that depends on a number of different symbolic variables and derivatives of those variables. ie. the terms in the vector x contain y, y', z, z', theta, theta' etc.

What I would like to do is use a command that replaces these variables and their derivatives with new variables with different names. ie. replace y, y', z, z', theta, theta' with x1, x2, x3, x4, x5, x6. Note that this isn't x1, x1', x3, x3' etc. Ie. the derivates have become new variables as well.

It seems like this is a fairly easy thing to do (it's certainly an easy thing to describe), but I'm struggling to find how to do it.

Thanks, and I appreciate any help!

------Background------

The reason I'm trying to rewrite / substitute the variables in this way is because I'm trying to get a number of equations into state-space form. However, the equations are non-linear, so I'm computing the jacobian of the states and evaluating it around an equilibrium position to linearise it.

My problem occurs when attempting to find the jacobian.

If x = [y; y'; z; z' ...] and x' = [y'; (some expression); z'; (some expression) ...]

Then Jacob(x', x) does not work.

Presumably this is because the function is struggling to partially differentiate with respect to a differential. ie. partially differentiating wrt y'. So I'm trying to replace the differentials with variables (x1, x2, x3 etc.). This will also make the equations easier to understand.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:ptc-5748870)

here's a worksheet

No, unfortunately its just a pic. Always better to post the sheet as an attachment itself.

Using y:=y(t), etc. sure is bad habit and I wouldn't recommomend doing it, regardless whether the symbolic eval looks OK or not. Dependencies should be shown by function arguments IMHO.

And you can't name the vector function AND its argument the same (x), Should be clear that this can't work as x can't be a function AND a vector at the same time.

I am still not sure if you really want/should replace your functions by variables at the end, but at least I think the attached is doing what you demanded.

17.03.png

View solution in original post

6 REPLIES 6

Do you mean you want to do something like this?

Jacob.PNG

Alan

Sort of.

Formulating it into functions with F(y,z,theta) is an obvious way to change the variables - thanks! So I can then call F(x1,x3,x5) to change the variables y, z, theta to x1, x3, x5.

However, lets say I have F(y, z) := y^2 + y.z + dy/dt

What I really want to say is: F(y, dy/dt, z) := y^2 + y.z + dy/dt

Which allows me to call F(x1, x2, x3)

This replaces the derivative dy/dt with a variable (x2) and removes it's dependence on y.

But you can't use an operator on the left hand side of the equation so I can't write F(dy/dt) := dy/dt

So the core of the question is, how do I replace a derivative with a variable? ie. replace dy/dt with x2?

Werner_E
25-Diamond I
(To:ptc-5748870)

Its not clear to me what you really are after.

You write variable but I suspect that you mean function or function name in some instances.

The way you setup your F(y,z) can't work anyway. If you write y^2 or y*z, y has to be a variable, but then you write dy/dt (which obviously should be dy(t)/dt, otherwise it would be constant zero) this implies y should be a function of t (y(t)) - a descrepancy. You also must decide if F should have two or three parameters (or maybe even four if you have to add the independent argument t)

Please state more clearly what you have in mind and post a worksheet showing how you would like your new function to be used and what you expect as result if all works as you intend. Also state if the goal is just a symbolic expression or a (numerically) working function.

It also seems to me you missed the syntax and meaning of Mathcads Jacob() when you expect something like Jacob(x',x) to work (unless of course x' has nothing to do with x other than x' being a vector function with argument x.) You may want to look up Jacob() in the help files.

The way I understand it so far I wonder why you dont formulate your function (or vector, as you wrote in your first post) in terms of variables x1,etc. and then call this function with your theta, etc. and their derivatives as actual paramter. But then I may be missing the missing point.

BTW, stating which version of Mathcad the questions relates to would be a good idea, too.

Sorry it wasn't clear. To answer some questions here's a worksheet adapting the example I gave above.

I've been very lax with defining all the parameters of the functions and as you say haven't been clear between functions and variables. Hopefully this will clear up what I'm trying to do:

example.png

What I am having difficulty with, representative in this example, is replacing dy(t)/dt with x2 and dz(t)/dt with x4. The actual functions I'm using are much larger so I can't do it by hand.

If this still doesn't make sense please let me know and I'll try to answer any questions.

Werner_E
25-Diamond I
(To:ptc-5748870)

here's a worksheet

No, unfortunately its just a pic. Always better to post the sheet as an attachment itself.

Using y:=y(t), etc. sure is bad habit and I wouldn't recommomend doing it, regardless whether the symbolic eval looks OK or not. Dependencies should be shown by function arguments IMHO.

And you can't name the vector function AND its argument the same (x), Should be clear that this can't work as x can't be a function AND a vector at the same time.

I am still not sure if you really want/should replace your functions by variables at the end, but at least I think the attached is doing what you demanded.

17.03.png

Brilliant, thanks for clearing a few things up there.

Announcements

Top Tags