用到的函数:


1、函数表达式已知
例:
y=x2y=x^2y=x2x=t2x=t^2x=t2
求yyy关于ttt的导数,代码如下所示:
syms x t
x = t^2;
y = x^2;
df = diff(y,t)
latex(df)
运行结果:
>> untitled
df =
4*t^3
ans =
'4\,t^3'
>>
Latex代码输入到markdown,结果如下所示:
4 t34\,t^34t3
2、函数表达式未知
例:
y=x2y=x^2y=x2x=f(t)x=f(t)x=f(t)
求yyy关于ttt的偏导数,代码如下所示:
syms x t
x = str2sym('x(t)');
y = x^2;
df = diff(y,t)
latex(df)
运行结果:
>> untitled
df =
2*x(t)*diff(x(t), t)
ans =
'2\,x\left(t\right)\,\frac{\partial }{\partial t} x\left(t\right)'
>>
Latex代码输入到markdown,结果如下所示:
2 x(t) ∂∂tx(t)2\,x\left(t\right)\,\frac{\partial }{\partial t} x\left(t\right)2x(t)∂t∂x(t)
一处错误:
之前在2、函数表达式未知这里,用的是如下代码:
syms x t
x = sym('x(t)');
y = x^2;
df = diff(y,t)
latex(df)
报错:
>> untitled
错误使用 sym>convertChar (line 1548)
Character vectors and strings in the first argument can only specify a variable or number. To
evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.
出错 sym>tomupad (line 1255)
S = convertChar(x);
出错 sym (line 222)
S.s = tomupad(x);
出错 untitled (line 3)
x = sym('x(t)');
解决办法:用str2sym代替sym
682

被折叠的 条评论
为什么被折叠?



