matlab subs命令,subs --matlab符号表示式中符号变量替换命令

subs

Symbolic substitution in a symbolic expression_r or matrix

Syntax

R = subs(S)

R = subs(S, new)

R = subs(S,old,new)

Description

subs(S) replaces all occurrences of variables in the symbolic

expression_r S with values obtained from the calling function, or the

MATLAB workspace.

subs(S, new) replaces the default symbolic variable in S with

new.

subs(S,old,new) replaces old with new in the symbolic expression_r

S. old is a symbolic variable or a string representing a variable

name. new is a symbolic or numeric variable or expression_r.

If old and new are cell arrays of the same size, each element of

old is replaced by the corresponding element of new. If S and old

are scalars and new is an array or cell array, the scalars are

expanded to produce an array result. If new is a cell array of

numeric matrices, the substitutions are performed elementwise

(i.e., subs(x*y,{x,y},{A,B}) returns A.*B when A and B are

numeric).

If subs(s,old,new) does not change s, subs(s,new,old)is tried.

This provides backwards compatibility with previous versions and

eliminates the need to remember the order of the arguments.

subs(s,old,new) does not switch the arguments if s does not

change.

Note If A

is a matrix, the command subs(S, x, A) replaces all occurrences of

the variable x in the symbolic expression_r S with the matrix A, and

replaces the constant term in S with the constant times a matrix of

all ones. To uate S in the matrix sense, use the command

polyvalm(sym2poly(S), A), which replaces the constant term with the

constant times an identity matrix.

Examples

Single

Input.

Suppose a = 980 and C1 = 3 exist in the workspace.

The statement

y = dsolve('Dy = -a*y')

produces

y = C1*exp(-a*t)

Then the statement

subs(y)

produces

ans = 3*exp(-980*t)

Single Substitution.

subs(a+b,a,4) returns 4+b.

Multiple

Substitutions.

subs(cos(a)+sin(b),{a,b},{sym('alpha'),2}) returns

cos(alpha)+sin(2)

Scalar Expansion

Case.

subs(exp(a*t),'a',-magic(2)) returns

[ exp(-t), exp(-3*t)]

[ exp(-4*t), exp(-2*t)]

Multiple Scalar

Expansion.

subs(x*y,{x,y},{[0 1;-1 0],[1 -1;-2 1]}) returns

0 -1

2 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值