EDA365电子论坛网

标题: matlab中的assume函数 [打印本页]

作者: thinkfunny    时间: 2021-1-22 10:17
标题: matlab中的assume函数
本帖最后由 thinkfunny 于 2021-1-22 10:20 编辑 8 m; b$ Y* [0 B8 Z8 |6 q" x6 L, Q  g

. B6 |% d8 Y: `3 fAssume: W" l2 S4 A% o2 ]
Syntax
9 o+ k1 B3 z" J5 v: M- T4 v7 \$ V% eDescription
- T) l3 }( x5 K7 I' D" L* G4 QExamples% q9 t+ a2 k9 _  j( d  k
Common Assumptions
; C( @0 y/ r: ^0 s" `0 S6 @Assume Variable Is Even or Odd
2 ^0 Q; e  f6 G" c' d4 }1 V0 w$ TMultiple Assumptions. ^& L6 e% _9 c% @  B0 B* s
Assumptions on Integrand# F; v' \8 n2 ^* r5 [3 q+ v
Assumptions on Parameters and Variables of Equation" y7 I3 q  f0 {1 p+ e
Use Assumptions for Simplification" l0 E8 j9 O  D' a! U
Assumptions on Expressions3 w" _+ x  N8 Q. h
Assumptions to Prove Relations
" J  B% R5 G) y* pAssumptions on Matrix Elements* G7 O% I3 s% q0 s
Tips! S0 j9 z3 u9 f4 ~4 g
Set assumption on symbolic objectcollapse all in page2 a' d! b' E! E. f, ]- j
! b$ O% p9 h6 A  g% b' U& S1 _
( s: Q$ `" Z. {# C% Z
Syntax
( F$ `, d  {$ M) wassume(condition). U. r* n2 Y( X% ~- A2 h
assume(expr,set)
- ]1 u; W& F1 d) ?1 massume(expr,‘clear’)& g# L' h/ }% b, Z7 u% x

$ R9 C+ x9 R1 a' N6 e6 b
' w; g- o0 b7 a; |0 fDescription9 V2 @1 j5 t5 k
assume(condition) states that condition is valid. assume is not additive. Instead, it automatically deletes all previous assumptions on the variables in condition.6 M! f6 n0 f3 t% o5 z$ F! G

) j. Z/ y9 l: O1 X# b2 F8 Cassume(expr,set) states that expr belongs to set. assume deletes previous assumptions on variables in expr.3 ?4 N+ B  v3 P6 t

$ R1 |6 T8 a6 |  d4 r. }assume(expr,'clear') clears all assumptions on all variables in expr.) \) Z: h2 W; k9 |8 m1 o

" d8 a$ A$ c& B
& v2 Y# r' x: Y1 E* s: o$ c. ?2 E8 {Examples
; B, `+ m' @3 x1 o1 e1 HCommon Assumptions
) ~6 U4 O6 |9 E/ `/ tSet an assumption using the associated syntax.
" _+ o/ E6 _- x( [, D7 P8 h1 @6 O/ r% P/ N( m! r8 B: d8 g

  d# K; ]4 j+ M- u% P 4 T4 ^9 \- H% r* V: U
0 n! t* N# o# ?! w. M
' r( f. T" W0 \" {, |
1 }  `) q: s" g

2 @& q: q! Z6 q7 W9 g$ @Assume Variable Is Even or Odd
+ ?' \* n9 ?6 U" ?  H) w0 E4 z) A+ U, _, `3 Z

) S; g# @! `( h) l* LAssume x is even by assuming that x/2 is an integer. Assume x is odd by assuming that (x-1)/2 is an integer.8 ^  v* H' L' h0 @/ z# b
$ W1 `/ S- @! d

, G% F( L/ @- {
, {- _" D" ?) {3 o
  D; S2 N$ M4 [/ G+ C' l! a/ B) Z8 `' k& @) I- K% [, o. m
+ a, U4 H* a4 g8 F! p% }3 q0 G
5 N  y) E0 T2 L" M, _& T
4 h1 m8 I- _" E/ g

6 R, O8 \6 O& K. y+ F* H2 |  T' O' i7 `: W
$ W1 h6 X2 G$ U+ F1 W$ D* [! K

/ p- c5 _5 s/ r% y5 J, G2 Y1 L2 \( b5 O
Multiple Assumptions6 o- f* m3 E" [( A) z
Successive assume commands do not set multiple assumptions. Instead, each assume command deletes previous assumptions and sets new assumptions. Set multiple assumptions by using assumeAlso or the & operator.
& X' q8 a. y! w9 U* |/ }/ D) G$ d' @7 F: c: i  u
连续的assume命令不会设置多个假设。相反,每个assume命令都会删除以前的假设并设置新的假设。使用assumeAlso或&运算符可以设置多个假设。
! E6 d5 }7 E9 v% N2 N
, w2 Z0 H5 }7 ]/ m5 j; @Assume x > 5 and then x < 10 by using assume. Use assumptions to check that only the second assumption exists because assume deleted the first assumption when setting the second.% P/ `7 W  b8 P! Z' U+ I

7 v; X/ x$ U- g: ~' R9 D1 x. n4 v0 M& m% w, M( R/ M
. S6 M4 f) Y, p

8 t% g2 U8 J" ^' Q+ c( `' _
5 x1 N, Q0 X3 @& l. h" x+ eAssume the first assumption in addition to the second by using assumeAlso. Check that both assumptions exist.
9 D) l6 A5 v) g8 H' S" S6 x. c6 Y, r$ i$ O9 F/ X
$ b3 E, f7 l" D6 x+ V7 n2 |: u
! ?% T: E# J2 C6 B
# y/ U; }$ F: s

4 v$ d! m2 n# F5 v8 m4 q5 QClear the assumptions on x.: _9 k+ ?% V$ R

+ t' u! F6 l& d/ x9 Q) n3 [2 Y) z) d) L; w' U: t
/ t0 G9 m. _& R! K; L9 b
Assume both conditions using the & operator. Check that both assumptions exist.$ t! R+ `; M! u' B# i" E+ q

% O* D" q' h% G" D. b, U2 Y7 s7 R# Q6 R+ q& Y* k

5 @. I4 T) u  S) y' l- \" e( _( f
5 R& w+ ?* s$ i5 s, b* E/ y  I* A! e
) d6 [3 N& F7 q( S  WClear the assumptions on x for future calculations.* d8 t/ V* x  K* R0 ^
% [" F5 v8 R( e2 B
' ]. {; c/ k# v9 d* ]/ q6 h

6 F% }" Z# {) f# R  QAssumptions on Integrand" e( p" `6 u- S9 |5 n% b
Compute an indefinite integral with and without the assumption on the symbolic parameter a.* e2 k" w3 [6 b% E
, s- z0 R$ Q$ V, {0 }, `
Use assume to set an assumption that a does not equal -1.
& t0 M9 Q$ l; k+ J* O+ g+ T4 B1 S& v

9 M" _# t* r5 t3 v6 I+ U6 \, a6 c& R7 @2 c6 |
Compute this integral.计算积分: _; g1 A9 J% Z) W1 g0 [

! y* A( w4 e4 g' D( z: z% o+ v9 e* x# X2 w$ ?' Z, i* u& H

+ c1 m0 ~: S1 K0 ^* \1 B
) f) V* m: o& {; |5 _3 K
# |! _) r  R  R& fNow, clear the assumption and compute the same integral. Without assumptions, int returns this piecewise result.6 o' ]9 I. `- U8 T$ |
7 o1 O; c0 i0 ?5 g( L. F; ]2 c
. D8 |( ]. P+ [' L6 z' q0 i

5 Q- {4 y4 U" T9 f/ Y+ X1 w$ [2 s5 e; x# c9 j% l' I
4 K8 z2 \8 L9 k# T
Assumptions on Parameters and Variables of Equation* q4 ~% y5 _, G
Use assumptions to restrict the returned solutions of an equation to a particular interval.( n. w0 o$ T" w7 H, v( b
( d5 p+ q# C& X' V) ]' ~
Solve this equation.) f( \/ q# t! S) u8 h

4 u) |9 K+ ^0 v) S% }% f3 t2 m( {" T5 [2 `3 F- x* x' A

" _4 e8 J8 @9 l: A5 @: P( V* v6 x/ I1 T

1 E  F/ k7 }: N& }* R& p0 ~Use assume to restrict the solutions to the interval –1 <= x <= 1.
" L* l% C9 O6 @. y, o: [- E/ S1 X6 `) W- ?4 o4 V

, }2 g5 m, s3 G* d  G7 n# {  |% o0 k9 J+ C% C
5 a* E& R$ R3 q! d+ U
; ]$ B4 m. f  L! x# L" l
Set several assumptions simultaneously by using the logical operators and, or, xor, not, or their shortcuts. For example, all negative solutions less than -1 and all positive solutions greater than 1.
9 P: X: |4 d& O* d9 D! g# B, V6 D8 Y1 w4 B
, @$ g) H! R4 J9 S& ]* c
$ t: o4 C% @& O8 S/ u& ^+ p. J
2 U7 \5 ~% k3 Z# x4 N

0 a; s+ h4 z, F5 eFor further computations, clear the assumptions.
& M3 p5 [1 e( b$ Z' e- z; v0 G0 ~
: f9 e& [% \2 ^/ g" n
1 Z, Z# N( ~6 ~% Y3 `7 {* P. Y3 @4 P& T6 A
Use Assumptions for Simplification
, ?) y* i3 h0 I0 |6 r0 pSetting appropriate assumptions can result in simpler expressions.+ P6 @4 I7 t6 ~0 o

, e0 X% B/ R; B( x" R8 ETry to simplify the expression sin(2pin) using simplify. The simplify function cannot simplify the input and returns the input as it is.: w: k4 W/ T5 k) t
/ i+ X+ J) m* x& P

# A* O6 L9 \+ T: ?) D  k
& G$ F/ J( h' t6 `# _1 V! G
3 Y8 M% Y' T/ }- a0 D) r; t6 f7 |: p! u) M% {5 ]/ O
Assume n is an integer. simplify now simplifies the expression.1 Z7 Y; T1 T( ?4 W5 z
2 a; b  X; V/ h
: B$ s+ J& B& v2 G; S$ I
+ C. M% @; ^8 Z7 R$ C: G: z
8 i2 g9 E- Z+ s8 l

! J/ J3 s* s/ p' g4 b8 LFor further computations, clear the assumption.
# D5 m& C% e1 ]% H; Q) l& F1 }1 }2 X4 D' r$ I3 j

6 \% m$ [9 v7 R" K9 d/ M& w7 H9 P, z9 J2 [; I% Q; b" x4 u
Assumptions on Expressions
0 A* Q# V4 [* [' w" o5 Y1 ^# GSet assumption on the symbolic expression.+ g: T% _2 z7 r# ~/ l, {

2 X7 U2 `: i5 ]  s6 g8 fYou can set assumptions not only on variables, but also on expressions. For example, compute this integral.
  R7 s; @9 g+ u/ O( F' \; r! k
! {/ l8 {: h: b/ h: x/ r' F
5 {  L. e$ }8 e& J& \$ \$ j: s/ i3 b) @
4 _  W& ~; s+ w. O5 d- V8 w% H

1 K7 C, a' e1 g9 \4 h, ^- v. `% n/ kSet the assumption x2 – 1 > 0 to produce a simpler result.  `( i9 {3 e2 r) z- o- q% k
6 t1 k6 |' I) r% N! {& X3 p
0 K$ l( e- G3 k( g: A
5 C  s% `3 U. k8 M5 g( w9 a
/ r/ a+ c) v' b# D* N5 V+ j2 k7 C
( Z4 e( t& `! V& D  Y
For further computations, clear the assumption.9 V5 i) X1 k' S+ I2 n/ d  X

4 u( O* u; V' d; ~) N0 T1 F, N  Z0 J' g# m3 r( ^  a
1 C4 K4 h7 ?7 k+ Z/ U# s
Assumptions to Prove Relations
* d; s# f- b, V' i( {Prove relations that hold under certain conditions by first assuming the conditions and then using isAlways.% E8 G) [% g- |) i7 i- u! [
6 B( }* w0 m/ o: ?( ^
Prove that sin(pi*x) is never equal to 0 when x is not an integer. The isAlways function returns logical 1 (true), which means the condition holds for all values of x under the set assumptions.) t$ I5 b" F! }& v; k
' B* v7 ?4 m8 U; _1 O4 J
) i5 Q) Q* j1 T* U/ |. ~9 ]

& u. H) G4 z3 s; B" Y9 o  w* e. n# a8 r0 ^9 P0 N  O/ m

! m9 _5 [# K4 l, g- uAssumptions on Matrix Elements8 G* h" y: `* K/ h& q
Set assumptions on all elements of a matrix using sym.% S) G$ n6 q9 h4 X- V

2 i6 c+ s& K- S& Z% V8 w; w2 QCreate the 3-by-3 symbolic matrix A with auto-generated elements. Specify the set as rational.
9 t, l; I& A% ]& }6 ]+ B5 ]
5 o. c0 F8 d( u) Z0 f/ x+ z
( I: E6 h2 m5 E2 _; d& v% |% a# h

) w& V; A7 X8 U7 N. d( H
2 h$ C& G! p& m2 F& SReturn the assumptions on the elements of A using assumptions.& E3 u" n$ n. X0 ~# g1 [2 d
5 L) F! \+ D0 E% p5 b$ ?  V; U( e
+ Z  r6 {1 X) [6 q% L# {
9 F/ }- V# ]% c( H) Q) M* T
+ D. G5 `1 }. Y% U% _

4 T* T( @2 z# c# ?# Z/ L4 l1 RYou can also use assume to set assumptions on all elements of a matrix. Assume all elements of A are positive using assume.
! y# {; R* i- x* J6 [3 t, a1 O, Y, F1 x. O2 E
$ M- q5 g5 T3 C, q$ F4 I9 i7 V/ U

  H, |1 L0 ~* ~: _* A; i6 zFor further computations, clear the assumptions.
; O& S  F- ]/ H! o! h7 @0 B
; {% \# P& U0 h$ g, ^4 r. T7 s' X$ W9 U; f1 N

$ B+ `9 T; }- A9 p8 kTips0 U9 E5 X- d- r

6 w* m. x" |6 j: W0 p0 j7 Z$ H9 M( l* u* r* [7 B$ i* }5 m
      assume(var,'clear')
' d' F' u8 N6 `% E( |  p4 h# B% O/ t' H* \" [' h2 J
       clear all
5 p3 ?; B" B% X& N% _0 R. z  p+ q; Z* ]3 b

: t; u8 p7 D, Q3 D0 g
. p% z* q) C: x# h/ a4 K
. V( P, ]' q3 ]& W: R" e
( s1 H* m# @8 C: b( M% y) y& \  P2 q7 N: ?0 X3 U
or more efficiently:2 E) ~3 j+ Q+ A" M" B6 t
# j9 l8 ^! t+ d$ T
2 A& A6 L2 F, |2 m' J5 R

作者: NingW    时间: 2021-1-22 11:01
matlab中的assume函数




欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/) Powered by Discuz! X3.2