Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> A=[0 0 1; 1 0 2; 3 4 2];
- >> B=[0 1 0]'
- B =
- 0
- 1
- 0
- >> c=[1 0 0]
- c =
- 1 0 0
- >> p=ctrb(A, B)
- p =
- 0 0 4
- 1 0 8
- 0 4 8
- >> P=p
- P =
- 0 0 4
- 1 0 8
- 0 4 8
- >> C=c
- C =
- 1 0 0
- >> clc(c)
- Error using clc
- Too many input arguments.
- >> clear(c)
- Error using clear
- Argument must contain a character vector.
- >> clean(c)
- Undefined function or variable 'clean'.
- Did you mean:
- >> clear(c)
- Error using clear
- Argument must contain a character vector.
- >> obsv(A,C)
- ans =
- 1 0 0
- 0 0 1
- 3 4 2
- >> A=[1 0 0; 0 0 1; 0 4 0]
- A =
- 1 0 0
- 0 0 1
- 0 4 0
- >> P=ctrb(A, B)
- P =
- 0 0 0
- 1 0 4
- 0 4 0
- >> B=
- B=
- ↑
- Error: Expression or statement is incomplete or incorrect.
- >> B
- B =
- 0
- 1
- 0
- >> A=[-2 0 0; 0 0 -3; 0 2 -3]
- A =
- -2 0 0
- 0 0 -3
- 0 2 -3
- >> syms h1 h2 h3
- >> H=[h1 h2 h3]
- H =
- [ h1, h2, h3]
- >> Acl = A+B*H
- Acl =
- [ -2, 0, 0]
- [ h1, h2, h3 - 3]
- [ 0, 2, -3]
- >> syms lambda
- >> polycar = det(lambda*eye(3)-Ac1)
- Undefined function or variable 'Ac1'.
- Did you mean:
- >> polycar = det(lambda*eye(3)-Acl)
- polycar =
- 12*lambda - 4*h3 - 6*h2 - 5*h2*lambda - 2*h3*lambda - h2*lambda^2 + 5*lambda^2 + lambda^3 + 12
- >> collect(polycar)
- ans =
- lambda^3 + (5 - h2)*lambda^2 + (12 - 2*h3 - 5*h2)*lambda - 6*h2 - 4*h3 + 12
- >> factor(polycar)
- ans =
- [ lambda + 2, 3*lambda - 2*h3 - 3*h2 - h2*lambda + lambda^2 + 6]
- >> A
- A =
- -2 0 0
- 0 0 -3
- 0 2 -3
- >> B
- B =
- 0
- 1
- 0
- >> C
- C =
- 1 0 0
- >> collect(factor(polycar))
- ans =
- [ lambda + 2, lambda^2 + (3 - h2)*lambda - 3*h2 - 2*h3 + 6]
- >> (lambda+4)*(lambda+5)
- ans =
- (lambda + 4)*(lambda + 5)
- >> expand(ans)
- ans =
- lambda^2 + 9*lambda + 20
- >> help solve
- solve Symbolic solution of algebraic equations.
- S = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN)
- S = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN,'ReturnConditions',true)
- [S1,...,SN] = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN)
- [S1,...,SN,params,conds] = solve(eqn1,...,eqnM,var1,var2,...,varN,'ReturnConditions',true)
- The eqns are symbolic expressions, equations, or inequalities. The
- vars are symbolic variables specifying the unknown variables.
- If the expressions are not equations or inequalities,
- solve seeks zeros of the expressions.
- Otherwise solve seeks solutions.
- If not specified, the unknowns in the system are determined by SYMVAR,
- such that their number equals the number of equations.
- If no analytical solution is found, a numeric solution is attempted;
- in this case, a warning is printed.
- Three different types of output are possible. For one variable and one
- output, the resulting solution is returned, with multiple solutions to
- a nonlinear equation in a symbolic vector. For several variables and
- several outputs, the results are sorted in the same order as the
- variables var1,var2,...,varN in the call to solve. In case no variables
- are given in the call to solve, the results are sorted in lexicographic
- order and assigned to the outputs. For several variables and a single
- output, a structure containing the solutions is returned.
- solve(...,'ReturnConditions', VAL) controls whether solve should in
- addition return a vector of all newly generated parameters to express
- infinite solution sets and about conditions on the input parameters
- under which the solutions are correct.
- If VAL is TRUE, parameters and conditions are assigned to the last two
- outputs. Thus, if you provide several outputs, their number must equal
- the number of specified variables plus two.
- If you provide a single output, a structure is returned
- that contains two additional fields 'parameters' and 'conditions'.
- No numeric solution is attempted even if no analytical solution is found.
- If VAL is FALSE, then solve may warn about newly generated parameters or
- replace them automatically by admissible values. It may also fall back
- to the numerical solver.
- The default is FALSE.
- solve(...,'IgnoreAnalyticConstraints',VAL) controls the level of
- mathematical rigor to use on the analytical constraints of the solution
- (branch cuts, division by zero, etc). The options for VAL are TRUE or
- FALSE. Specify FALSE to use the highest level of mathematical rigor
- in finding any solutions. The default is FALSE.
- solve(...,'PrincipalValue',VAL) controls whether solve should return multiple
- solutions (if VAL is FALSE), or just a single solution (when VAL is TRUE).
- The default is FALSE.
- solve(...,'IgnoreProperties',VAL) controls if solve should take
- assumptions on variables into account. VAL can be TRUE or FALSE.
- The default is FALSE (i.e., take assumptions into account).
- solve(...,'Real',VAL) allows to put the solver into "real mode."
- In "real mode," only real solutions such that all intermediate values
- of the input expression are real are searched. VAL can be TRUE or FALSE.
- The default is FALSE.
- solve(...,'MaxDegree',n) controls the maximum degree of polynomials
- for which explicit formulas will be used during the computation.
- n must be a positive integer. The default is 3.
- Example 1:
- syms p x r
- solve(p*sin(x) == r) chooses 'x' as the unknown and returns
- ans =
- asin(r/p)
- pi - asin(r/p)
- Example 2:
- syms x y
- [Sx,Sy] = solve(x^2 + x*y + y == 3,x^2 - 4*x + 3 == 0) returns
- Sx =
- 1
- 3
- Sy =
- 1
- -3/2
- Example 3:
- syms x y
- S = solve(x^2*y^2 - 2*x - 1 == 0,x^2 - y^2 - 1 == 0) returns
- the solutions in a structure.
- S =
- x: [8x1 sym]
- y: [8x1 sym]
- Example 4:
- syms a u v
- [Su,Sv] = solve(a*u^2 + v^2 == 0,u - v == 1) regards 'a' as a
- parameter and solves the two equations for u and v.
- Example 5:
- syms a u v w
- S = solve(a*u^2 + v^2,u - v == 1,a,u) regards 'v' as a
- parameter, solves the two equations, and returns S.a and S.u.
- When assigning the result to several outputs, the order in which
- the result is returned depends on the order in which the variables
- are given in the call to solve:
- [U,V] = solve(u + v,u - v == 1, u, v) assigns the value for u to U
- and the value for v to V. In contrast to that
- [U,V] = solve(u + v,u - v == 1, v, u) assigns the value for v to U
- and the value of u to V.
- Example 6:
- syms a u v
- [Sa,Su,Sv] = solve(a*u^2 + v^2,u - v == 1,a^2 - 5*a + 6) solves
- the three equations for a, u and v.
- Example 7:
- syms x
- S = solve(x^(5/2) == 8^(sym(10/3))) returns all three complex solutions:
- S =
- 16
- - 4*5^(1/2) - 4 + 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
- - 4*5^(1/2) - 4 - 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
- Example 8:
- syms x
- S = solve(x^(5/2) == 8^(sym(10/3)), 'PrincipalValue', true)
- selects one of these:
- S =
- - 4*5^(1/2) - 4 + 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
- Example 9:
- syms x
- S = solve(x^(5/2) == 8^(sym(10/3)), 'IgnoreAnalyticConstraints', true)
- ignores branch cuts during internal simplifications and, in this case,
- also returns only one solution:
- S =
- 16
- Example 10:
- syms x
- S = solve(sin(x) == 0) returns 0
- S = solve(sin(x) == 0, 'ReturnConditions', true) returns a structure expressing
- the full solution:
- S.x = k*pi
- S.parameters = k
- S.conditions = in(k, 'integer')
- Example 11:
- syms x y real
- [S, params, conditions] = solve(x^(1/2) = y, x, 'ReturnConditions', true)
- assigns solution, parameters and conditions to the outputs.
- In this example, no new parameters are needed to express the solution:
- S =
- y^2
- params =
- Empty sym: 1-by-0
- conditions =
- 0 <= y
- Example 12:
- syms a x y
- [x0, y0, params, conditions] = solve(x^2+y, x, y, 'ReturnConditions', true)
- generates a new parameter z to express the infinitely many solutions.
- This z can be any complex number, both solutions are valid without
- restricting conditions:
- x0 =
- -(-z)^(1/2)
- (-z)^(1/2)
- y0 =
- z
- z
- params =
- z
- conditions =
- true
- true
- Example 13:
- syms t positive
- solve(t^2-1)
- ans =
- 1
- solve(t^2-1, 'IgnoreProperties', true)
- ans =
- 1
- -1
- Example 14:
- solve(x^3-1) returns all three complex roots:
- ans =
- 1
- - 1/2 + (3^(1/2)*i)/2
- - 1/2 - (3^(1/2)*i)/2
- solve(x^3-1, 'Real', true) only returns the real root:
- ans =
- 1
- See also dsolve, subs.
- Reference page for solve
- >> [h2 h3]=solve('9=3 - h2','- 3*h2 - 2*h3 + 6')
- Warning: Support of character vectors that are not valid variable names or define a number will be removed in a future release. To create symbolic expressions, first create
- symbolic variables and then use operations on them.
- > In sym>convertExpression (line 1559)
- In sym>convertChar (line 1464)
- In sym>tomupad (line 1216)
- In sym (line 179)
- In solve>getEqns (line 405)
- In solve (line 225)
- Warning: Support of character vectors that are not valid variable names or define a number will be removed in a future release. To create symbolic expressions, first create
- symbolic variables and then use operations on them.
- > In sym>convertExpression (line 1559)
- In sym>convertChar (line 1464)
- In sym>tomupad (line 1216)
- In sym (line 179)
- In solve>getEqns (line 405)
- In solve (line 225)
- Warning: Do not specify equations and variables as character vectors. Instead, create symbolic variables with syms.
- > In solve>getEqns (line 445)
- In solve (line 225)
- h2 =
- -6
- h3 =
- 12
- >> H=[23425243 -6 12]
- H =
- 23425243 -6 12
- >> eig(A+B*H]
- eig(A+B*H]
- ↑
- Error: Unbalanced or unexpected parenthesis or bracket.
- Did you mean:
- >> eig(A+B*H)
- ans =
- -0.0000
- -9.0000
- -2.0000
- >> clear H h1 h2 h3
- >> syms h1 h2 h3
- >> H=[h1, h2, h3]
- H =
- [ h1, h2, h3]
- >> eig(A+B*H)
- ans =
- -2
- h2/2 - (h2^2 + 6*h2 + 8*h3 - 15)^(1/2)/2 - 3/2
- h2/2 + (h2^2 + 6*h2 + 8*h3 - 15)^(1/2)/2 - 3/2
- >> A
- A =
- -2 0 0
- 0 0 -3
- 0 2 -3
- >>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement