Can I change the formula of a symbolic function in MATLAB?

◇◆丶佛笑我妖孽 提交于 2020-01-16 19:17:51

问题


I have the following code:

syms t x;
e=symfun(x-t,[x,t]);

In the problem I want to solve x is a function of t but I only know its value at the given t,so I modeled it here as a variable.I want to differentiate e with respect to time without "losing" x,so that I can then substitute it with x'(t) which is known to me. In another question of mine here,someone suggested that I write the following:

e=symfun(exp(t)-t,[t]);

and after the differentiation check if I can substitute exp(t) with the value of x'(t).

Is this possible?Is there any other neater way?


回答1:


I'm really not sure I understand what you're asking (and I didn't understand your other question either), but here's an attempt.

Since, x is a function of time, let's make that explicit by making it what the help and documentation for symfun calls an "abstract" or "arbitrary" symbolic function, i.e., one without a definition. In Matlab R2014b:

syms t x(t);
e = symfun(x-t,t)

which returns

e(t) =

x(t) - t

Taking the derivative of the symfun function e with respect to time:

edot = diff(e,t)

returns

edot(t) =

D(x)(t) - 1

the expression for edot(t) is a function of the derivative of x with respect to time:

xdot = diff(x,t)

which is the abstract symfun:

xdot(t) =

D(x)(t)

Now, I think you want to be able to substitute a specific value for xdot (xdot_given) into e(t) for t at t_given. You should be able to do this just using subs, e.g., something like this:

sums t_given xdot_given;
edot_t_given = subs(edot,{t,xdot},{t_given, xdot_given});

You may not need to substitute t if the only parts of edot that are a function of time are the xdot parts.



来源:https://stackoverflow.com/questions/25227675/can-i-change-the-formula-of-a-symbolic-function-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!