Advertisement
Guido_Fe

Automatica

May 18th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. >> A=[0 0 1; 1 0 2; 3 4 2];
  2. >> B=[0 1 0]'
  3.  
  4. B =
  5.  
  6. 0
  7. 1
  8. 0
  9.  
  10. >> c=[1 0 0]
  11.  
  12. c =
  13.  
  14. 1 0 0
  15.  
  16. >> p=ctrb(A, B)
  17.  
  18. p =
  19.  
  20. 0 0 4
  21. 1 0 8
  22. 0 4 8
  23.  
  24. >> P=p
  25.  
  26. P =
  27.  
  28. 0 0 4
  29. 1 0 8
  30. 0 4 8
  31.  
  32. >> C=c
  33.  
  34. C =
  35.  
  36. 1 0 0
  37.  
  38. >> clc(c)
  39. Error using clc
  40. Too many input arguments.
  41.  
  42. >> clear(c)
  43. Error using clear
  44. Argument must contain a character vector.
  45.  
  46. >> clean(c)
  47. Undefined function or variable 'clean'.
  48.  
  49. Did you mean:
  50. >> clear(c)
  51. Error using clear
  52. Argument must contain a character vector.
  53.  
  54. >> obsv(A,C)
  55.  
  56. ans =
  57.  
  58. 1 0 0
  59. 0 0 1
  60. 3 4 2
  61.  
  62. >> A=[1 0 0; 0 0 1; 0 4 0]
  63.  
  64. A =
  65.  
  66. 1 0 0
  67. 0 0 1
  68. 0 4 0
  69.  
  70. >> P=ctrb(A, B)
  71.  
  72. P =
  73.  
  74. 0 0 0
  75. 1 0 4
  76. 0 4 0
  77.  
  78. >> B=
  79. B=
  80. Error: Expression or statement is incomplete or incorrect.
  81.  
  82. >> B
  83.  
  84. B =
  85.  
  86. 0
  87. 1
  88. 0
  89.  
  90. >> A=[-2 0 0; 0 0 -3; 0 2 -3]
  91.  
  92. A =
  93.  
  94. -2 0 0
  95. 0 0 -3
  96. 0 2 -3
  97.  
  98. >> syms h1 h2 h3
  99. >> H=[h1 h2 h3]
  100.  
  101. H =
  102.  
  103. [ h1, h2, h3]
  104.  
  105. >> Acl = A+B*H
  106.  
  107. Acl =
  108.  
  109. [ -2, 0, 0]
  110. [ h1, h2, h3 - 3]
  111. [ 0, 2, -3]
  112.  
  113. >> syms lambda
  114. >> polycar = det(lambda*eye(3)-Ac1)
  115. Undefined function or variable 'Ac1'.
  116.  
  117. Did you mean:
  118. >> polycar = det(lambda*eye(3)-Acl)
  119.  
  120. polycar =
  121.  
  122. 12*lambda - 4*h3 - 6*h2 - 5*h2*lambda - 2*h3*lambda - h2*lambda^2 + 5*lambda^2 + lambda^3 + 12
  123.  
  124. >> collect(polycar)
  125.  
  126. ans =
  127.  
  128. lambda^3 + (5 - h2)*lambda^2 + (12 - 2*h3 - 5*h2)*lambda - 6*h2 - 4*h3 + 12
  129.  
  130. >> factor(polycar)
  131.  
  132. ans =
  133.  
  134. [ lambda + 2, 3*lambda - 2*h3 - 3*h2 - h2*lambda + lambda^2 + 6]
  135.  
  136. >> A
  137.  
  138. A =
  139.  
  140. -2 0 0
  141. 0 0 -3
  142. 0 2 -3
  143.  
  144. >> B
  145.  
  146. B =
  147.  
  148. 0
  149. 1
  150. 0
  151.  
  152. >> C
  153.  
  154. C =
  155.  
  156. 1 0 0
  157.  
  158. >> collect(factor(polycar))
  159.  
  160. ans =
  161.  
  162. [ lambda + 2, lambda^2 + (3 - h2)*lambda - 3*h2 - 2*h3 + 6]
  163.  
  164. >> (lambda+4)*(lambda+5)
  165.  
  166. ans =
  167.  
  168. (lambda + 4)*(lambda + 5)
  169.  
  170. >> expand(ans)
  171.  
  172. ans =
  173.  
  174. lambda^2 + 9*lambda + 20
  175.  
  176. >> help solve
  177. solve Symbolic solution of algebraic equations.
  178. S = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN)
  179. S = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN,'ReturnConditions',true)
  180.  
  181. [S1,...,SN] = solve(eqn1,eqn2,...,eqnM,var1,var2,...,varN)
  182. [S1,...,SN,params,conds] = solve(eqn1,...,eqnM,var1,var2,...,varN,'ReturnConditions',true)
  183.  
  184. The eqns are symbolic expressions, equations, or inequalities. The
  185. vars are symbolic variables specifying the unknown variables.
  186. If the expressions are not equations or inequalities,
  187. solve seeks zeros of the expressions.
  188. Otherwise solve seeks solutions.
  189. If not specified, the unknowns in the system are determined by SYMVAR,
  190. such that their number equals the number of equations.
  191. If no analytical solution is found, a numeric solution is attempted;
  192. in this case, a warning is printed.
  193.  
  194. Three different types of output are possible. For one variable and one
  195. output, the resulting solution is returned, with multiple solutions to
  196. a nonlinear equation in a symbolic vector. For several variables and
  197. several outputs, the results are sorted in the same order as the
  198. variables var1,var2,...,varN in the call to solve. In case no variables
  199. are given in the call to solve, the results are sorted in lexicographic
  200. order and assigned to the outputs. For several variables and a single
  201. output, a structure containing the solutions is returned.
  202.  
  203. solve(...,'ReturnConditions', VAL) controls whether solve should in
  204. addition return a vector of all newly generated parameters to express
  205. infinite solution sets and about conditions on the input parameters
  206. under which the solutions are correct.
  207. If VAL is TRUE, parameters and conditions are assigned to the last two
  208. outputs. Thus, if you provide several outputs, their number must equal
  209. the number of specified variables plus two.
  210. If you provide a single output, a structure is returned
  211. that contains two additional fields 'parameters' and 'conditions'.
  212. No numeric solution is attempted even if no analytical solution is found.
  213. If VAL is FALSE, then solve may warn about newly generated parameters or
  214. replace them automatically by admissible values. It may also fall back
  215. to the numerical solver.
  216. The default is FALSE.
  217.  
  218. solve(...,'IgnoreAnalyticConstraints',VAL) controls the level of
  219. mathematical rigor to use on the analytical constraints of the solution
  220. (branch cuts, division by zero, etc). The options for VAL are TRUE or
  221. FALSE. Specify FALSE to use the highest level of mathematical rigor
  222. in finding any solutions. The default is FALSE.
  223.  
  224. solve(...,'PrincipalValue',VAL) controls whether solve should return multiple
  225. solutions (if VAL is FALSE), or just a single solution (when VAL is TRUE).
  226. The default is FALSE.
  227.  
  228. solve(...,'IgnoreProperties',VAL) controls if solve should take
  229. assumptions on variables into account. VAL can be TRUE or FALSE.
  230. The default is FALSE (i.e., take assumptions into account).
  231.  
  232. solve(...,'Real',VAL) allows to put the solver into "real mode."
  233. In "real mode," only real solutions such that all intermediate values
  234. of the input expression are real are searched. VAL can be TRUE or FALSE.
  235. The default is FALSE.
  236.  
  237. solve(...,'MaxDegree',n) controls the maximum degree of polynomials
  238. for which explicit formulas will be used during the computation.
  239. n must be a positive integer. The default is 3.
  240.  
  241. Example 1:
  242. syms p x r
  243. solve(p*sin(x) == r) chooses 'x' as the unknown and returns
  244.  
  245. ans =
  246. asin(r/p)
  247. pi - asin(r/p)
  248.  
  249. Example 2:
  250. syms x y
  251. [Sx,Sy] = solve(x^2 + x*y + y == 3,x^2 - 4*x + 3 == 0) returns
  252.  
  253. Sx =
  254. 1
  255. 3
  256.  
  257. Sy =
  258. 1
  259. -3/2
  260.  
  261. Example 3:
  262. syms x y
  263. S = solve(x^2*y^2 - 2*x - 1 == 0,x^2 - y^2 - 1 == 0) returns
  264. the solutions in a structure.
  265.  
  266. S =
  267. x: [8x1 sym]
  268. y: [8x1 sym]
  269.  
  270. Example 4:
  271. syms a u v
  272. [Su,Sv] = solve(a*u^2 + v^2 == 0,u - v == 1) regards 'a' as a
  273. parameter and solves the two equations for u and v.
  274.  
  275. Example 5:
  276. syms a u v w
  277. S = solve(a*u^2 + v^2,u - v == 1,a,u) regards 'v' as a
  278. parameter, solves the two equations, and returns S.a and S.u.
  279.  
  280. When assigning the result to several outputs, the order in which
  281. the result is returned depends on the order in which the variables
  282. are given in the call to solve:
  283. [U,V] = solve(u + v,u - v == 1, u, v) assigns the value for u to U
  284. and the value for v to V. In contrast to that
  285. [U,V] = solve(u + v,u - v == 1, v, u) assigns the value for v to U
  286. and the value of u to V.
  287.  
  288. Example 6:
  289. syms a u v
  290. [Sa,Su,Sv] = solve(a*u^2 + v^2,u - v == 1,a^2 - 5*a + 6) solves
  291. the three equations for a, u and v.
  292.  
  293. Example 7:
  294. syms x
  295. S = solve(x^(5/2) == 8^(sym(10/3))) returns all three complex solutions:
  296.  
  297. S =
  298. 16
  299. - 4*5^(1/2) - 4 + 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
  300. - 4*5^(1/2) - 4 - 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
  301.  
  302. Example 8:
  303. syms x
  304. S = solve(x^(5/2) == 8^(sym(10/3)), 'PrincipalValue', true)
  305. selects one of these:
  306.  
  307. S =
  308. - 4*5^(1/2) - 4 + 4*2^(1/2)*(5 - 5^(1/2))^(1/2)*i
  309.  
  310. Example 9:
  311. syms x
  312. S = solve(x^(5/2) == 8^(sym(10/3)), 'IgnoreAnalyticConstraints', true)
  313. ignores branch cuts during internal simplifications and, in this case,
  314. also returns only one solution:
  315.  
  316. S =
  317. 16
  318.  
  319. Example 10:
  320. syms x
  321. S = solve(sin(x) == 0) returns 0
  322.  
  323. S = solve(sin(x) == 0, 'ReturnConditions', true) returns a structure expressing
  324. the full solution:
  325.  
  326. S.x = k*pi
  327. S.parameters = k
  328. S.conditions = in(k, 'integer')
  329.  
  330. Example 11:
  331. syms x y real
  332. [S, params, conditions] = solve(x^(1/2) = y, x, 'ReturnConditions', true)
  333. assigns solution, parameters and conditions to the outputs.
  334. In this example, no new parameters are needed to express the solution:
  335.  
  336. S =
  337. y^2
  338.  
  339. params =
  340. Empty sym: 1-by-0
  341.  
  342. conditions =
  343. 0 <= y
  344.  
  345. Example 12:
  346. syms a x y
  347. [x0, y0, params, conditions] = solve(x^2+y, x, y, 'ReturnConditions', true)
  348. generates a new parameter z to express the infinitely many solutions.
  349. This z can be any complex number, both solutions are valid without
  350. restricting conditions:
  351.  
  352. x0 =
  353. -(-z)^(1/2)
  354. (-z)^(1/2)
  355.  
  356. y0 =
  357. z
  358. z
  359.  
  360. params =
  361. z
  362.  
  363. conditions =
  364. true
  365. true
  366.  
  367. Example 13:
  368. syms t positive
  369. solve(t^2-1)
  370.  
  371. ans =
  372. 1
  373.  
  374. solve(t^2-1, 'IgnoreProperties', true)
  375.  
  376. ans =
  377. 1
  378. -1
  379.  
  380. Example 14:
  381. solve(x^3-1) returns all three complex roots:
  382.  
  383. ans =
  384. 1
  385. - 1/2 + (3^(1/2)*i)/2
  386. - 1/2 - (3^(1/2)*i)/2
  387.  
  388. solve(x^3-1, 'Real', true) only returns the real root:
  389.  
  390. ans =
  391. 1
  392.  
  393. See also dsolve, subs.
  394.  
  395. Reference page for solve
  396.  
  397. >> [h2 h3]=solve('9=3 - h2','- 3*h2 - 2*h3 + 6')
  398. 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
  399. symbolic variables and then use operations on them.
  400. > In sym>convertExpression (line 1559)
  401. In sym>convertChar (line 1464)
  402. In sym>tomupad (line 1216)
  403. In sym (line 179)
  404. In solve>getEqns (line 405)
  405. In solve (line 225)
  406. 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
  407. symbolic variables and then use operations on them.
  408. > In sym>convertExpression (line 1559)
  409. In sym>convertChar (line 1464)
  410. In sym>tomupad (line 1216)
  411. In sym (line 179)
  412. In solve>getEqns (line 405)
  413. In solve (line 225)
  414. Warning: Do not specify equations and variables as character vectors. Instead, create symbolic variables with syms.
  415. > In solve>getEqns (line 445)
  416. In solve (line 225)
  417.  
  418. h2 =
  419.  
  420. -6
  421.  
  422.  
  423. h3 =
  424.  
  425. 12
  426.  
  427. >> H=[23425243 -6 12]
  428.  
  429. H =
  430.  
  431. 23425243 -6 12
  432.  
  433. >> eig(A+B*H]
  434. eig(A+B*H]
  435. Error: Unbalanced or unexpected parenthesis or bracket.
  436.  
  437. Did you mean:
  438. >> eig(A+B*H)
  439.  
  440. ans =
  441.  
  442. -0.0000
  443. -9.0000
  444. -2.0000
  445.  
  446. >> clear H h1 h2 h3
  447. >> syms h1 h2 h3
  448. >> H=[h1, h2, h3]
  449.  
  450. H =
  451.  
  452. [ h1, h2, h3]
  453.  
  454. >> eig(A+B*H)
  455.  
  456. ans =
  457.  
  458. -2
  459. h2/2 - (h2^2 + 6*h2 + 8*h3 - 15)^(1/2)/2 - 3/2
  460. h2/2 + (h2^2 + 6*h2 + 8*h3 - 15)^(1/2)/2 - 3/2
  461.  
  462. >> A
  463.  
  464. A =
  465.  
  466. -2 0 0
  467. 0 0 -3
  468. 0 2 -3
  469.  
  470. >>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement