gino_examples.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ## Simple example of creating an octave polynomial symbolically
  2. P = g2o_pol("s^2*(s+a)*(s+b)^3") # Create symbolic polynomial in octave form
  3. a = 1; b = 2; # Give a and b numerical values
  4. p = eval(P) # Create numerical polynomial
  5. roots(p) # Use p in any appropriate octave
  6. # function
  7. ## More complicated example of symbolic linearisation
  8. ## ODE dx/dt = f(x,u); y = g(x,u)
  9. f_1 = "x_2 - beta*tanh(u_1)";
  10. f_2 = "-x_1 + x_2^2 + u_1";
  11. g_1 = "x_1";
  12. f = go_list(f_1,f_2)
  13. g = go_list(g_1)
  14. ## Linearise via symbolic differentiation
  15. [A,B,C,D] = go_lin(f,g)
  16. ## Find the transfer function
  17. I = "[[1,0],[0,1]]"; # Unit matrix
  18. ## Create G as a string: C(sI-A)^-1B + D
  19. G_str = sprintf("%s*((s*%s-%s)^(-1))*%s + %s", C,I,A,B,D)
  20. ## Find G itself
  21. G = g_evalm(G_str);
  22. ## Substitute steady-state values
  23. G = g_subs(G, "{u_1,x_1,x_2}", "{0,0,0}")
  24. ## Extract the (only) matrix element
  25. G = g_op(G,"0")
  26. ## Find numerator and denominator
  27. a = g2o_pol(g_denom(G))
  28. b = g2o_pol(g_numer(G))
  29. ## Evaluate numerically
  30. beta = 0.5;
  31. b = eval(b)
  32. a = eval(a)