我的代码如下:syms q x star;qd=symfun(90*pi/180+30*pi/180*cos(q),[q]);p=symfun(79*pi/180*exp(-1.25*q)+pi/180,[q]);T=log(-(1+star)/star);e=symfun(x-qd,[x,q]);例如,我想以的形式编写函数 @(t,y)(⁄ T( ⁄ )+ ⁄ T(⁄ ))解决方案我不确定实现细节,但总的来说,这是您可以采用的一种方法.它涉及两个步骤.在T(.)函数中的用exp(t)替换x时,用这种方法进行微分时exp(t)始终停留在此处以便进行高阶导数,并且外部函数将相对于同时.在执行diff之后,您应该收到一个包含exp(t)的表达式(未经测试,希望如此).此时,exp(t)是x的时间导数.现在,您只需要在t中评估此表达式.这样做时,您需要用x的派生替换exp(t).我不知道是否可以做到这一点,如果不能,那么可以使用y代替exp(t)并使用约束y=exp(t)来做到这一点,但是您需要自己弄清楚正确的实现.在这里您需要在右侧的t处替换x的导数.如果您没有在特定点t处的值,请执行我在注释中建议的操作.预先在许多点上预先计算并在此步骤中进行插值.这种方法依赖于将x(t)与exp(t)交换,如果那不起作用,那么我将按照注释中的建议进行操作.通过已知函数近似x(t),并在代码中使用它代替x.I want to differentiate the following function wrt in MATLAB:T(⁄)My problem is that I know the derivatives of x numerically (I am inside a kind of odefun).I want to use diff to make my code generalizeable for high order derivatives,but the derivatives of x are now constant. I would also like all this to be in an anonymous function where I can make the differentiation and substitute accordingly the time and the derivative of x needed,so that I don't have to write multiple functions for every state of my system.My code is as follows:syms q x star;qd=symfun(90*pi/180+30*pi/180*cos(q),[q]);p=symfun(79*pi/180*exp(-1.25*q)+pi/180,[q]);T=log(-(1+star)/star);e=symfun(x-qd,[x,q]);and I want to write for example a function in the form@(t,y)(⁄ T(⁄)+⁄ T(⁄)+T(⁄)) 解决方案 I am not sure of the implementation details but in general this is one approach that you could take. It involves two steps.in the T(.) function replace x with exp(t) this way when you do the differentiation exp(t) always stays there for the higher order derivatives to be taken and the outer functions will be differentiated with respect to x at the same time. After you do diff you should receive an expression that contains exp(t) (not tested so hopefully it is the case). At this point exp(t) is your time derivative of x. Now you only need to evaluate this expression in t. When doing so you need to replace exp(t) by the derivative of x. I do not know if this can be done, if not then perhaps using y instead of exp(t) with the constraint y=exp(t) would do it but you need to figure the correct implementation out yourself.Here you need to substitute the derivative of x at the right t. If you do not have the value at the particular point t then do what I suggested in the comment. Pre-calculate it beforehand in many points and interpolate in this step.This approach relies on swapping x(t) with exp(t) if that does not work then I would do what I suggested in the comment. Approximate x(t) by a known function and use that instead of x in your code. 这篇关于函数的导数在数值上已知的MATLAB微分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 03:59
查看更多