How do i define a variable as a function?

1 次查看(过去 30 天)
Let us say there is a fucntion theta that is depedent on time: Theta(t); It is in a cos function so: cos(theta(t))
How do i differentiate this in matlab so it uses the chain rule?
clear all
syms t theta
theta=t;
f=cos(theta(t));
diff(f,t)
I have tried the above and got the errors:
Error using sym/subsref (line 49)
Error using maplemex
Error, (in MTM:-subsref) indices must be positive integers, got t
Error in test (line 5)
f=cos(theta(t));

采纳的回答

Star Strider
Star Strider 2021-10-11
I suspect this works the similiarly in Maple (that I do not currently have) —
syms t theta(t)
f=cos(theta(t));
dfdt(t) = diff(f,t)
dfdt(t) = 
.
  7 个评论
Hamza Yusuf
Hamza Yusuf 2021-10-11
The other solution where you remove the matlab directory worked. Thank you,
Star Strider
Star Strider 2021-10-11
I hope that you do not have to uninstall Maple, and can simply disconnect it from MATLAB.
However if you need to uninstall it (and then reinstall it without connecting it to MATLAB next time), and since it appears that you are using Windows, open Control Panel, then click on Programs and Features, then follow the instructions. Then, reinstall Maple without connecting it to MATLAB.
.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2021-10-11
syms theta(t)
f=cos(theta(t));
diff(f,t)
  1 个评论
Hamza Yusuf
Hamza Yusuf 2021-10-11
I get this error:
Error using assignin
Invalid variable name "theta(t)" in ASSIGNIN.
Error in syms (line 47)
assignin('caller',varargin{1},sym(varargin{1}));
Error in test (line 1)
syms theta(t)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by