用Matlab推导公式

用到的函数:
syms函数
str2sym函数


1、函数表达式已知
例:
y = x 2 y=x^2 y=x2 x = t 2 x=t^2 x=t2
y y y关于 t t t的导数,代码如下所示:

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   t 3 4\,t^3 4t3
2、函数表达式未知
例:

y = x 2 y=x^2 y=x2 x = f ( t ) x=f(t) x=f(t)
y y y关于 t t t的偏导数,代码如下所示:

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 )   ∂ ∂ t x ( t ) 2\,x\left(t\right)\,\frac{\partial }{\partial t} x\left(t\right) 2x(t)tx(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

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值