用 matlab 推导公式

用 matlab 推导公式

随学习进度持续更新。。。

1 先学会如何对一个未知函数进行操作

参考 https://www.cnblogs.com/yuehq/p/6501547.html

代码

syms t m
x = sym('x(t,m)'); %定义x是关于t的一个表达式
y = sin(x);
df = diff(y,t) %得到表达式结果
latex(df) %转换为latex代码
df = subs(df,x,t^2*m) %将x表达式代入
latex(df) %转换为latex代码

结果如下:

df =
 
cos(x(t, m))*diff(x(t, m), t)
 

ans =

    '\cos\left(x\left(t,m\right)\right)\,\frac{\partial }{\partial t} x\left(t,m\right)'

 
df =
 
2*m*t*cos(m*t^2)
 

ans =

    '2\,m\,t\,\cos\left(m\,t^2\right)'

推导结果输入到markdown中效果如下:
cos ⁡ ( x ( t , m ) )   ∂ ∂ t x ( t , m ) \cos\left(x\left(t,m\right)\right)\,\frac{\partial }{\partial t} x\left(t,m\right) cos(x(t,m))tx(t,m)

2   m   t   cos ⁡ ( m   t 2 ) 2\,m\,t\,\cos\left(m\,t^2\right) 2mtcos(mt2)

2 生成任意大小符号矩阵

M = sym('A',[5,4]) %生成符号矩阵
latex(M)

result:

M =
 
[ A1_1, A1_2, A1_3, A1_4]
[ A2_1, A2_2, A2_3, A2_4]
[ A3_1, A3_2, A3_3, A3_4]
[ A4_1, A4_2, A4_3, A4_4]
[ A5_1, A5_2, A5_3, A5_4]
ans =

    '\left(\begin{array}{cccc} A_{1,1} & A_{1,2} & A_{1,3} & A_{1,4}\\ A_{2,1} & A_{2,2} & A_{2,3} & A_{2,4}\\ A_{3,1} & A_{3,2} & A_{3,3} & A_{3,4}\\ A_{4,1} & A_{4,2} & A_{4,3} & A_{4,4}\\ A_{5,1} & A_{5,2} & A_{5,3} & A_{5,4} \end{array}\right)'

latex:
( A 1 , 1 A 1 , 2 A 1 , 3 A 1 , 4 A 2 , 1 A 2 , 2 A 2 , 3 A 2 , 4 A 3 , 1 A 3 , 2 A 3 , 3 A 3 , 4 A 4 , 1 A 4 , 2 A 4 , 3 A 4 , 4 A 5 , 1 A 5 , 2 A 5 , 3 A 5 , 4 ) \left(\begin{array}{cccc} A_{1,1} & A_{1,2} & A_{1,3} & A_{1,4}\\ A_{2,1} & A_{2,2} & A_{2,3} & A_{2,4}\\ A_{3,1} & A_{3,2} & A_{3,3} & A_{3,4}\\ A_{4,1} & A_{4,2} & A_{4,3} & A_{4,4}\\ A_{5,1} & A_{5,2} & A_{5,3} & A_{5,4} \end{array}\right) A1,1A2,1A3,1A4,1A5,1A1,2A2,2A3,2A4,2A5,2A1,3A2,3A3,3A4,3A5,3A1,4A2,4A3,4A4,4A5,4

try:

syms m n
N = sym('x',[m,n])

failed:

错误使用 sym (line 224)
The second argument must be an assumption or a size vector.

版本问题
感谢@大家安静啊 的提醒,博主自己更新2019b后尝试操作确实有报错:

>> syms t m
>> x = sym('x(t,m')
错误使用 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);

原因是matlab更新了这个用法,在sym的文档中有说明,感觉syms更好用了。
在这里插入图片描述测试:

>> syms x(m,t)
>> x
 
x(m, t) =
 
x(m, t)
 
>> sin(x)
 
ans(m, t) =
 
sin(x(m, t))

搞定!

  • 6
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值