diff --git a/notebooks/alt/Octsim/@DTTransferFunction/DTTransferFunction.m b/notebooks/alt/Octsim/@DTTransferFunction/DTTransferFunction.m
index dd52c5fcffd245f73d4be98d67f910b5919f3152..a6d9e5a8077d31067b41d38621fdd16debe6b578 100644
--- a/notebooks/alt/Octsim/@DTTransferFunction/DTTransferFunction.m
+++ b/notebooks/alt/Octsim/@DTTransferFunction/DTTransferFunction.m
@@ -1,9 +1,14 @@
classdef DTTransferFunction < DTBlock
properties
- A
- B
- C
- D
+ #A
+ #B
+ #C
+ #D
+ num
+ den
+ nn
+ bufn
+ bufd
end
methods
function c = DTTransferFunction(in,out,num,den,Ts)
@@ -13,24 +18,43 @@ classdef DTTransferFunction < DTBlock
c.inpos(1) = in;
c.outpos(1) = out;
c.Ts = Ts;
+ c.num = num;
+ c.den = den;
sys = tf(num,den,Ts);
sysss= ss(sys);
- c.A = sysss.A;
- c.B = sysss.B;
- c.C = sysss.C;
- c.D = sysss.D;
- c.nstate = size(c.A,1);
- c.x = zeros(c.nstate,1);
+ #c.A = sysss.A;
+ #c.B = sysss.B;
+ #c.C = sysss.C;
+ #c.D = sysss.D;
+ #c.nstate = size(c.A,1);
+ #c.x = zeros(c.nstate,1);
+ c.nn = size(c.den,2);
+ nt = size(c.num,2);
+ c.bufd = zeros(c.nn,1);
+ c.bufn = zeros(c.nn,1);
+ dif = c.nn - nt;
+ c.num = [zeros(1,dif) c.num];
end
function updatediscrete(c)
- c.y = c.C*c.x+c.D*c.u';
- c.x=c.A*c.x+c.B*c.u';
+ #c.y = c.C*c.x+c.D*c.u';
+ #c.x=c.A*c.x+c.B*c.u';
+ for i=c.nn:-1:2
+ c.bufn(i) = c.bufn(i-1);
+ end
+ c.bufn(1) = c.u;
+ for i=c.nn:-1:2
+ c.bufd(i) = c.bufd(i-1);
+ end
+ c.bufd(1) = (c.num*c.bufn-c.den(2:c.nn)*c.bufd(2:c.nn))/c.den(1);
+ c.y = c.bufd(1);
flag = 1;
end
function flag = Reset(b)
- b.x = zeros(c.nstate,1);
+ #b.x = zeros(c.nstate,1);
+ b.bufn = zeros(b.nn,1);
+ b.bufd = zeros(b.nn,1);
flag = 1;
end
diff --git a/notebooks/exam example/V5.ipynb b/notebooks/exam example/V5.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..93095e1f9d60077db49c697e4a62c84583391820
--- /dev/null
+++ b/notebooks/exam example/V5.ipynb
@@ -0,0 +1,452 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "6cfcdd9e-6413-43fd-bb20-950c852ec0f7",
+ "metadata": {},
+ "source": [
+ "# <span style='color:OrangeRed'>V5 ZUSTANDRAUMDARSTELLUNG</span>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "9653081e-df65-4ccd-9204-e11c542a469f",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Gegeben ist ein Roboterarm, dessen rotatorische Bewegung durch die folgende gewöhnliche\n",
+ "Differentialgleichung beschrieben wird:\n",
+ "y¨(t) + 2 y˙(t) = 4K u(t)\n",
+ "Es bezeichnet hierbei y(t) den Drehwinkel des Roboterarms und u(t) = M(t)\n",
+ "das Drehmoment des Roboterarm-Servomotors. Für den Parameter K gilt: K = 2,4.\n",
+ "Ferner gilt y¨(0) = y˙(0) = y(0) = 0."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "e050a273-a079-40b9-ac0c-194e5e7f12e8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "% Necessary to use control toolbox\n",
+ "pkg load control\n",
+ "clear all"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "880aa4ff-2004-4875-affc-5759aba8104e",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Leiten Sie die zeitkontinuierliche Zustandsraumdarstellung für den Roboterarm her\n",
+ "und geben Sie das Model."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a27e62db-897e-41e8-9b56-fd8c6b48f3bf",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Das Zustandsraummodel des Roboterarms hat zwei Zustände: der Drehwinkel und die Ableitung des Drehwinkel"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "ef3d3be5-73cd-48d2-a773-d177b638230a",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "K = 2.4000\n"
+ ]
+ }
+ ],
+ "source": [
+ "K = 2.4"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "1943a7dc-b837-4623-8792-a1775026155d",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Die Koeffizienten der Differentialgleichungen zweiter Ordnung sind dann so definiert"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "402f525f-8a64-4584-8d05-dbd5e42e5516",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "a1 = 1\n",
+ "a2 = 2\n",
+ "a3 = 0\n",
+ "b1 = 9.6000\n"
+ ]
+ }
+ ],
+ "source": [
+ "a1 = 1\n",
+ "a2 = 2\n",
+ "a3 = 0\n",
+ "b1 = 4*K"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "971a3f7a-3c0d-4a88-895f-3777326d7440",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Die entsprechenden Matrizen für den Zustandsraum sind wie folgt definiert"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "id": "d8ab8054-efd1-4987-9600-24dbe480a40e",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "A =\n",
+ "\n",
+ " 0 1\n",
+ " 0 -2\n",
+ "\n",
+ "B =\n",
+ "\n",
+ " 0.00000\n",
+ " 9.60000\n",
+ "\n",
+ "C =\n",
+ "\n",
+ " 1 0\n",
+ "\n",
+ "D = 0\n"
+ ]
+ }
+ ],
+ "source": [
+ "A = [0 1;a3 -a2/a1]\n",
+ "B = [0; b1]\n",
+ "C = [1 0]\n",
+ "D = 0"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "9d90b015-72bf-4fb8-82a0-4ec0701232f6",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Diskretisieren Sie das Zustandsraummodel(unter Berücksichtigung\n",
+ "eines Haltegliedes 0. Ordnung). Verwenden Sie hierbei zur Berechnung\n",
+ "der Fundamentalmatrix das Cayley-Hamilton Theorem. Die Abtastzeit beträgt\n",
+ "Ts = 0,1 sec."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "8629e5a2-ae35-418d-8a65-7e511440917e",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Als ersten Schritt müssen wir die Eigenwerte berechnen"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "id": "1ed03ed5-3913-4107-95c9-f48e52bb50ee",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "p =\n",
+ "\n",
+ " -2\n",
+ " 0\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "p = eigs(A)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "0353e887-ebe2-44d0-b7fb-a191622cabff",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Dann wenden wir das Caley-Hamilton-Theorem an"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "id": "0d90c253-316f-47ed-9f7b-561ff0ed4868",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Ac =\n",
+ "\n",
+ " 1 -2\n",
+ " 1 0\n",
+ "\n",
+ "Bc =\n",
+ "\n",
+ " 0.81873\n",
+ " 1.00000\n",
+ "\n",
+ "alfa =\n",
+ "\n",
+ " 1.000000\n",
+ " 0.090635\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "Ts = 0.1;\n",
+ "Ac = [1 p(1);1 p(2)]\n",
+ "Bc = [expm(p(1)*Ts);expm(p(2)*Ts)]\n",
+ "alfa = inv(Ac)*Bc"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d4fac333-e43d-49c7-aaec-6168b86bd6a6",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "und dann:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "828217c8-bd90-42da-8b36-9e1f05727a24",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Fi =\n",
+ "\n",
+ " 1.00000 0.09063\n",
+ " 0.00000 0.81873\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "Fi = alfa(1)*eye(2)+alfa(2)*A"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a6ed8d3e-8d76-451c-8480-7182a8723ab2",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Wir Konnen vergleichen unsere Berechnungen mit Octave:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "058ad783-d553-4bcc-873c-a6f521c16975",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Fio =\n",
+ "\n",
+ " 1.00000 0.09063\n",
+ " 0.00000 0.81873\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "Fio = expm(A*Ts)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "63fb7dec-c4e2-4e53-b6f9-bea0649fd521",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Die andere Matrix können wir so berechnen:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
+ "id": "0c2d94f8-536c-421a-98ae-69771c0e6ca2",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "warning: passing floating-point values to sym is dangerous, see \"help sym\"\n",
+ "warning: called from\n",
+ " double_to_sym_heuristic at line 50 column 7\n",
+ " sym at line 379 column 13\n",
+ " int at line 138 column 7\n",
+ "warning: passing floating-point values to sym is dangerous, see \"help sym\"\n",
+ "warning: called from\n",
+ " double_to_sym_heuristic at line 50 column 7\n",
+ " sym at line 379 column 13\n",
+ " numeric_array_to_sym at line 36 column 16\n",
+ " sym at line 359 column 7\n",
+ " mtimes at line 63 column 5\n",
+ "Gi =\n",
+ "\n",
+ " 0.044954\n",
+ " 0.870092\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "pkg load symbolic\n",
+ "syms x\n",
+ "expr = expm(A*x);\n",
+ "Gi = eval(int(expr,x,0,Ts)*B)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "8a4be558-f51c-415e-96f7-922b8e417422",
+ "metadata": {},
+ "source": [
+ "<div style=\"font-family: 'times'; font-size: 13pt; text-align: justify\">\n",
+ "Zu vergleichen:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "id": "69e7fd06-f71a-48ec-af34-d2e406f9067c",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "sys.a =\n",
+ " x1 x2\n",
+ " x1 0 1\n",
+ " x2 0 -2\n",
+ "\n",
+ "sys.b =\n",
+ " u1\n",
+ " x1 0\n",
+ " x2 9.6\n",
+ "\n",
+ "sys.c =\n",
+ " x1 x2\n",
+ " y1 1 0\n",
+ "\n",
+ "sys.d =\n",
+ " u1\n",
+ " y1 0\n",
+ "\n",
+ "Continuous-time model.\n",
+ "\n",
+ "ans.a =\n",
+ " x1 x2\n",
+ " x1 1 0.09063\n",
+ " x2 0 0.8187\n",
+ "\n",
+ "ans.b =\n",
+ " u1\n",
+ " x1 0.04495\n",
+ " x2 0.8701\n",
+ "\n",
+ "ans.c =\n",
+ " x1 x2\n",
+ " y1 1 0\n",
+ "\n",
+ "ans.d =\n",
+ " u1\n",
+ " y1 0\n",
+ "\n",
+ "Sampling time: 0.1 s\n",
+ "Discrete-time model.\n"
+ ]
+ }
+ ],
+ "source": [
+ "sys = ss(A,B,C,D)\n",
+ "c2d(sys,Ts,'zoh')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "71ef35e6-15e0-441d-9d8e-58fccbd7bc8d",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Octave",
+ "language": "octave",
+ "name": "octave"
+ },
+ "language_info": {
+ "file_extension": ".m",
+ "help_links": [
+ {
+ "text": "GNU Octave",
+ "url": "https://www.gnu.org/software/octave/support.html"
+ },
+ {
+ "text": "Octave Kernel",
+ "url": "https://github.com/Calysto/octave_kernel"
+ },
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://metakernel.readthedocs.io/en/latest/source/README.html"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "octave",
+ "version": "5.2.0"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}