Question

I'm sorry if I'm not formerly correct; I would like to work with symbolic functions, like i.e. x(t) without the need to actually define x.

This may be useful because sometimes you'll have functions of x, and you want to calculate the derivative in t. For example

y(x) = y(x(t)) = t*x(t)

d y(x)             d x(t)
------  = x(t)+ t* ------
 d t                dt

Is there a way to accomplish this in matlab?

Était-ce utile?

La solution

Turns out this is pretty easy (after I spent 20 minutes making it very hard).

>> y = sym('t*x(t)')
>> y_dot = diff(y,t)
y_dot =
t*diff(x(t), t) + x(t)

You can also define some intermediates if you want

>> f = sym('x(t)');
>> y = t*f;
>> diff(y,'t')
ans =
t*diff(x(t), t) + x(t)

I also discovered the mupad command, which is worth trying out. Within the mupad window, type y(x) := t*x(t) and diff(y(x),t).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top