2026-01-27T15:19:25
This commit is contained in:
11
.auctex-auto/bib.el
Normal file
11
.auctex-auto/bib.el
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
;; -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(TeX-add-style-hook
|
||||||
|
"bib"
|
||||||
|
(lambda ()
|
||||||
|
(LaTeX-add-bibitems
|
||||||
|
"Midpoint"
|
||||||
|
"Trapez"
|
||||||
|
"Simpson"))
|
||||||
|
'(or :bibtex :latex))
|
||||||
|
|
||||||
8
.clang-format
Normal file
8
.clang-format
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
ColumnLimit: 80
|
||||||
|
...
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
*.log
|
||||||
|
tmp/
|
||||||
|
.gdb_history
|
||||||
BIN
AutoSW_Kronner_Topic-5.zip
Normal file
BIN
AutoSW_Kronner_Topic-5.zip
Normal file
Binary file not shown.
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
Topic 5: Numerical integration methods
|
||||||
|
|
||||||
|
compile with:
|
||||||
|
```bash
|
||||||
|
make clean
|
||||||
|
```
|
||||||
|
|
||||||
|
run with:
|
||||||
|
```bash
|
||||||
|
./main
|
||||||
|
```
|
||||||
24
bib.bib
Normal file
24
bib.bib
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
@misc{Midpoint,
|
||||||
|
title = {{Engineering at Alberta Courses {\ifmmode\mbox{\guillemotright}\else\guillemotright\fi} Rectangle Method}},
|
||||||
|
year = {2026},
|
||||||
|
month = jan,
|
||||||
|
note = {[Online; accessed 15. Jan. 2026]},
|
||||||
|
url = {https://engcourses-uofa.ca/books/numericalanalysis/numerical-integration/rectangle-method}
|
||||||
|
}
|
||||||
|
|
||||||
|
@misc{Trapez,
|
||||||
|
title = {{Engineering at Alberta Courses {\ifmmode\mbox{\guillemotright}\else\guillemotright\fi} Trapezoidal Rule}},
|
||||||
|
year = {2026},
|
||||||
|
month = jan,
|
||||||
|
note = {[Online; accessed 15. Jan. 2026]},
|
||||||
|
url = {https://engcourses-uofa.ca/books/numericalanalysis/numerical-integration/trapezoidal-rule}
|
||||||
|
}
|
||||||
|
|
||||||
|
@misc{Simpson,
|
||||||
|
title = {{Simpson's Rule (Simpson's 1/3 Rule) - Formula, Derivation, Examples}},
|
||||||
|
journal = {Cuemath},
|
||||||
|
year = {2026},
|
||||||
|
month = jan,
|
||||||
|
note = {[Online; accessed 15. Jan. 2026]},
|
||||||
|
url = {https://www.cuemath.com/simpsons-rule-formula}
|
||||||
|
}
|
||||||
20
documentation.bbl
Normal file
20
documentation.bbl
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
% $ biblatex auxiliary file $
|
||||||
|
% $ biblatex bbl format version 3.2 $
|
||||||
|
% Do not modify the above lines!
|
||||||
|
%
|
||||||
|
% This is an auxiliary file used by the 'biblatex' package.
|
||||||
|
% This file may safely be deleted. It will be recreated by
|
||||||
|
% biber as required.
|
||||||
|
%
|
||||||
|
\begingroup
|
||||||
|
\makeatletter
|
||||||
|
\@ifundefined{ver@biblatex.sty}
|
||||||
|
{\@latex@error
|
||||||
|
{Missing 'biblatex' package}
|
||||||
|
{The bibliography requires the 'biblatex' package.}
|
||||||
|
\aftergroup\endinput}
|
||||||
|
{}
|
||||||
|
\endgroup
|
||||||
|
|
||||||
|
\endinput
|
||||||
|
|
||||||
345
documentation.org
Normal file
345
documentation.org
Normal file
@@ -0,0 +1,345 @@
|
|||||||
|
#+title: Documentation for AutoSW
|
||||||
|
#+title: Topic 5: Numerical integration methods
|
||||||
|
#+author: Mia Kronner
|
||||||
|
#+author: Matr. 22201686
|
||||||
|
#+options: email:nil
|
||||||
|
|
||||||
|
#+bibliography: ./bib.bib
|
||||||
|
|
||||||
|
#+LATEX_HEADER: \let\oldsection\section
|
||||||
|
#+LATEX_HEADER: \renewcommand{\section}{\clearpage\oldsection}
|
||||||
|
#+LATEX_HEADER: \let\oldsubsection\subsection
|
||||||
|
#+LATEX_HEADER: \renewcommand{\subsection}{\clearpage\oldsubsection}
|
||||||
|
|
||||||
|
* Declaration of self reliance
|
||||||
|
I hereby declare that I have written this thesis independently in accordance with § 35 para. 7 RaPO (Framework Examination Regulations for Universities of Applied Sciences in Bavaria, BayRS 2210-4-1-4-1-WFK), have not submitted it elsewhere for examination purposes, have not used any sources or aids other than those indicated, and have marked all direct and indirect quotations as such.
|
||||||
|
|
||||||
|
* Graphical representation of the software design
|
||||||
|
|
||||||
|
|
||||||
|
#+BIND: org-latex-images-centered nil
|
||||||
|
#+ATTR_LATEX: \textwidth :float nil
|
||||||
|
[[./graphical-representation-white.drawio.png]]
|
||||||
|
|
||||||
|
* Theoretical explanation of the relationships
|
||||||
|
** ~"integrate.h"~:
|
||||||
|
Interface for ~integrate.c~ Module.
|
||||||
|
Here is declared:
|
||||||
|
- a void float function pointer for the mathematical function which is to be integrated ~integrand_f~.
|
||||||
|
- a typedef which contains the possible return values for the three integration functions ~integ_status_t~
|
||||||
|
- the three integration functions ~midpoint~ (rectangle midpoint method), ~trapezoid~ (trapezoid method), and ~simpson~ (simpson 1/3 method)
|
||||||
|
+ they each take a integrand function ~integrand_f f~, its context as a void pointer ~void *ctx~, the limits ~a~ and ~b~ and the number of intevals ~n~
|
||||||
|
|
||||||
|
#+name: integrate.h
|
||||||
|
#+begin_src C :noweb-ref integrate.h
|
||||||
|
#ifndef INTEGRATE_H_
|
||||||
|
#define INTEGRATE_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef float (*integrand_f)(float x, void *ctx);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
INTEG_OK = 0,
|
||||||
|
INTEG_ERR_BAD_ARGS = -1,
|
||||||
|
INTEG_ERR_N_EVEN_REQUIRED = -2
|
||||||
|
} integ_status_t;
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
#endif // INTEGRATE_H_
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** ~"integrate.c"~:
|
||||||
|
Implements the three numerical integration algorithms (midpoint/rectangle, trapezoid, Simpson 1/3) behind the public interface from ~integrate.h~, including argument validation and method-specific constraints.
|
||||||
|
|
||||||
|
The file includes ~integrate.h~ and provides the concrete implementations of ~midpoint()~, ~trapezoid()~, and ~simpson()~, each computing an approximation of $$I = \int_a^bf(x)dx$$ by sampling the integrand at specific points and summing weighted contributions.
|
||||||
|
|
||||||
|
All three functions follow the same reusable calling convention: function pointer ~integrand_f f~, a generic context pointer ~ctx~, integration bounds ~a~, ~b~, subinterval count ~n~, and output pointer ~out~.
|
||||||
|
|
||||||
|
#+name: integrate.c
|
||||||
|
#+begin_src C :noweb-ref integrate.c
|
||||||
|
|
||||||
|
static inline int bad_args(integrand_f f, float *a, float *b, unsigned *n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
return (f == NULL || out == NULL || *n == 0u || !(*b > *a));
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
|
||||||
|
float sum = 0.0f;
|
||||||
|
float fx = 0.0f;
|
||||||
|
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float x = a + 0.5f * h;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
fx = f(x, ctx);
|
||||||
|
sum = sum + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float sum = 0.5f * (f(a, ctx) + f(b, ctx));
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
sum = sum + f(x, ctx);
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
if (n & 1u) /*n must be even*/
|
||||||
|
{
|
||||||
|
return INTEG_ERR_N_EVEN_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sum_odd = 0.0f;
|
||||||
|
float sum_even = 0.0f;
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
const float fx = f(x, ctx);
|
||||||
|
if (i & 1u)
|
||||||
|
sum_odd = sum_odd + fx;
|
||||||
|
else
|
||||||
|
sum_even = sum_even + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out =
|
||||||
|
(h / 3.0f) * (f(a, ctx) + 4.0f * sum_odd + 2.0f * sum_even + f(b, ctx));
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Common argument checking (~bad_args~)
|
||||||
|
|
||||||
|
A shared internal helper ~bad_args()~ is implemented as ~static inline~ to reduce call overhead and to allow the compiler to inline it for performance on embedded targets.
|
||||||
|
|
||||||
|
It returns an error condition if ~f == NULL, out == NULL, n == 0~ or the interval is invalid (the code checks ~b > a~).
|
||||||
|
If ~bad_args()~ reports invalid inputs, each public integration function returns ~INTEG_ERR_BAD_ARGS~ immediately.
|
||||||
|
|
||||||
|
*** Midpoint / rectangle method (~midpoint~)
|
||||||
|
**** Mathematical idea
|
||||||
|
|
||||||
|
The interval [a,b] is split into n subintervals of equal width $$h=(b-a)/n$$, and each subinterval [xi,xi+1] is approximated by a rectangle whose height is the function value at the midpoint $$xi+h/2$$.
|
||||||
|
The Formula is as follows: [cite:@Midpoint]
|
||||||
|
|
||||||
|
$$\approx h \sum_{i=1}^n f({x_{i-1}+x_i}/2)$$
|
||||||
|
|
||||||
|
**** Implementation details
|
||||||
|
The code computes ~h~, initializes the first midpoint ~x = a + 0.5fh~, then loops exactly ~n~ times, accumulating ~sum = sum + f(x, ctx)~ and stepping ~x = x + h~.
|
||||||
|
|
||||||
|
Finally, the result is written as ~out = sum * h~ and the function returns ~INTEG_OK~.
|
||||||
|
|
||||||
|
*** Trapezoid method (~trapezoid~)
|
||||||
|
**** Mathematical idea
|
||||||
|
|
||||||
|
Each subinterval is approximated by a trapezoid formed by the points $$(xi,f(xi))$$ and $$(xi+1,f(xi+1))$$, giving the composite trapezoid rule.
|
||||||
|
|
||||||
|
This corresponds to the standard weighted sum [cite:@Trapez]
|
||||||
|
$$ = h/2 (f(x_0)+2f(x_1)+\dots+2f(x_{n-1})+f(x_n))$$
|
||||||
|
**** Implementation details
|
||||||
|
|
||||||
|
The code computes ~h~, then initializes ~sum = 0.5f*(f(a,ctx)+f(b,ctx))~ to apply the half-weight to the endpoints.
|
||||||
|
It iterates from the first interior node ~x = a + h~ for ~i = 1..n-1~, adds each interior sample once (~sum = sum + f(x,ctx)~), then scales by ~h~ via ~*out = sum * h~.
|
||||||
|
*** Simpson 1/3 method (~simpson~)
|
||||||
|
**** Mathematical idea
|
||||||
|
|
||||||
|
Simpson's 1/3 rule approximates the function by piecewise quadratic polynomials over pairs of subintervals, which leads to alternating weights 4 and 2 for interior points.
|
||||||
|
|
||||||
|
The composite Simpson rule requires an even number of subintervals nn so that the domain can be grouped into $$n/2$$ pairs.
|
||||||
|
The formula is as such: [cite:@Simpson]
|
||||||
|
$$ \approx (h/3) [f(x_0)+4f(x_1)+2f(x_2)+ \dots 2f(x_{n-2})+4f(x_{n-1})+f(x_n)]$$
|
||||||
|
|
||||||
|
**** Implementation details and constraint handling
|
||||||
|
|
||||||
|
After basic argument validation, the function checks ~if (n & 1u)~ and returns ~INTEG_ERR_N_EVEN_REQUIRED~ if ~n~ is odd, enforcing the "even n" requirement from the interface contract.
|
||||||
|
|
||||||
|
It then loops over the interior nodes ~i=1..n-1~ and accumulates two partial sums: ~sum_odd~ for odd indices (weight 4) and ~sum_even~ for even indices (weight 2).
|
||||||
|
The final formula implemented is \\
|
||||||
|
~out = (h/3)(f(a)+4*sum_odd+2*sum_even+f(b))~, which matches the documented Simpson weighting scheme.
|
||||||
|
|
||||||
|
** Performance-oriented aspects (embedded focus)
|
||||||
|
|
||||||
|
The design avoids dynamic allocation and uses a caller-provided output pointer (~float *out~), which is predictable and typical for embedded C modules.
|
||||||
|
|
||||||
|
The ~ctx~ pointer allows passing coefficients/parameters without global variables, enabling reuse for many function types while keeping the integrator code generic.
|
||||||
|
Using ~static inline~ for ~bad_args~ and keeping loop bodies simple (incrementing ~x~ by ~h~ rather than recomputing from scratch) supports compiler optimization and reduces runtime overhead.
|
||||||
|
|
||||||
|
When checking for evenness of ~n~ the simpson function uses ~& u1~ instead of ~% 2~. It is not possible to substitue a ~/2~ for a ~>>1~ for the float variable type. Such tricks can not have been used for any values with the float type.
|
||||||
|
|
||||||
|
* Documentation of the reference examples used for testing
|
||||||
|
~"main.c"~ is a small command-line test application that demonstrates how to use the reusable integration module by defining example integrand functions, calling all three numerical methods, and printing absolute errors against known exact results.
|
||||||
|
|
||||||
|
The application includes ~integrate.h~ and uses standard library functionality (printing and absolute error via ~fabsf~) to compare the numeric results to a known reference ("exact") value.
|
||||||
|
Its purpose is not to be a generic framework, but a compact test harness that exercises the module API and makes method limitations visible at runtime (e.g., Simpson's even-~n~ requirement).
|
||||||
|
|
||||||
|
** Test integrand design
|
||||||
|
Parameterized quadratic via context pointer
|
||||||
|
|
||||||
|
A small struct ~quad_t~ stores coefficients ~a2~, ~a1~, ~a0~ for a quadratic polynomial $$f(x)=a_2x^2+a_1x+a_0$$, showing how the integrator's ~void *ctx~ can carry user-defined parameters without globals.
|
||||||
|
The function ~f_quad(float x, void ctx)~ casts ~ctx~ to ~const quad_t~ and evaluates the polynomial, matching the generic ~integrand_f~ interface expected by the integration module.
|
||||||
|
|
||||||
|
** Test runner (~run_one~)
|
||||||
|
|
||||||
|
The helper ~run_one(...)~ calls ~midpoint~, ~trapezoid~, and ~simpson~ with the same function, bounds, and number of subintervals, storing results into three local floats (~r~, ~t~, ~s~).
|
||||||
|
It prints the integration problem setup (function name, bounds, ~n~), prints the exact reference value, and prints each method's absolute error using ~fabsf(result - exact)~ for a direct precision comparison.
|
||||||
|
Simpson's status return is checked: if ~simpson~ returns ~INTEG_OK~, the Simpson result/error is printed, otherwise a message is printed indicating it was not computed because ~n~ must be even.
|
||||||
|
|
||||||
|
** Reference examples in ~main()~
|
||||||
|
|
||||||
|
Four concrete test cases are instantiated using ~quad_t~ coefficients and passed to ~run_one~.
|
||||||
|
They have been chosen in such a way that many edge cases are accounted for.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Example 1: ~q~ $$f(x)=x^2$$ on [0,1] with exact integral 1/3 and ~n=10~
|
||||||
|
[[./q.png]]
|
||||||
|
|
||||||
|
Example 2: ~q2~ $$f(x)=-x2+3x+50$$ on [-3,15] with exact integral 90 and ~n=22~
|
||||||
|
[[./q2.png]]
|
||||||
|
|
||||||
|
Example 3: ~q3~ $$f(x)=-9x^2+3x-100$$ on [12,15] with exact integral -5119.5 and ~n=2~
|
||||||
|
[[./q3.png]]
|
||||||
|
|
||||||
|
Example 4: ~q4~ $$f(x)=6x^2-10x$$ on [-50,-5] with exact integral 262125 and ~n=6u~
|
||||||
|
[[./q4.png]]
|
||||||
|
#+name: main.c
|
||||||
|
#+begin_src C :noweb yes :results output :flags -g -fanalyzer
|
||||||
|
<<integrate.h>>
|
||||||
|
<<integrate.c>>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
float a2, a1, a0;
|
||||||
|
} quad_t;
|
||||||
|
|
||||||
|
static float f_quad(float x, void *ctx)
|
||||||
|
{
|
||||||
|
const quad_t *q = (const quad_t *)ctx;
|
||||||
|
return (q->a2 * x * x) + (q->a1 * x) + q->a0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_one(const char *name, integrand_f f, void *ctx, float a,
|
||||||
|
float b, float exact, unsigned n)
|
||||||
|
{
|
||||||
|
float r = 0.0f, t = 0.0f, s = 0.0f;
|
||||||
|
integ_status_t stS;
|
||||||
|
|
||||||
|
midpoint(f, ctx, a, b, n, &r);
|
||||||
|
trapezoid(f, ctx, a, b, n, &t);
|
||||||
|
|
||||||
|
stS = simpson(f, ctx, a, b, n, &s);
|
||||||
|
|
||||||
|
printf("\n%s on [%.6f, %.6f], n=%u\n", name, a, b, n);
|
||||||
|
printf("Exact: %.9f\n", exact);
|
||||||
|
printf("Midpoint: %.9f err=%.9f\n", r, fabsf(r - exact));
|
||||||
|
printf("Trapezoid: %.9f err=%.9f\n", t, fabsf(t - exact));
|
||||||
|
if (stS == INTEG_OK)
|
||||||
|
printf("Simpson: %.9f err=%.9f\n", s, fabsf(s - exact));
|
||||||
|
else
|
||||||
|
printf("Simpson: not computed (n must be even)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const quad_t q = {1.0f, 0.0f, 0.0f}; /*x^2*/
|
||||||
|
|
||||||
|
const quad_t q2 = {-1.0f, 3.0f, 50.0f}; /*x^2+3x+50*/
|
||||||
|
|
||||||
|
const quad_t q3 = {-9.0f, 3.0f, -100.0f}; /*-9x^2+3x-100*/
|
||||||
|
|
||||||
|
const quad_t q4 = {6.0f, -10.0f, 0.0f}; /*6x^2-10x*/
|
||||||
|
|
||||||
|
run_one("x^2", f_quad, (void *)&q, 0.0f, 1.0f, 1.0f / 3.0f, 10u);
|
||||||
|
|
||||||
|
run_one("x^2+3x+50", f_quad, (void *)&q2, -3.0f, 15.0f, 90.0f, 22u);
|
||||||
|
|
||||||
|
run_one("-9x^2+3x-100", f_quad, (void *)&q3, 12.0f, 15.0f, -5119.5f, 2u);
|
||||||
|
|
||||||
|
run_one("6x^2-10x", f_quad, (void *)&q4, -50.0f, -5.0f, 262125.0f, 6u);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Results
|
||||||
|
#+RESULTS: main.c
|
||||||
|
#+begin_results
|
||||||
|
x^2 on [0.000000, 1.000000], n=10
|
||||||
|
Exact: 0.333333343
|
||||||
|
Midpoint: 0.332500070 err=0.000833273
|
||||||
|
Trapezoid: 0.335000038 err=0.001666695
|
||||||
|
Simpson: 0.333333373 err=0.000000030
|
||||||
|
|
||||||
|
x^2+3x+50 on [-3.000000, 15.000000], n=22
|
||||||
|
Exact: 90.000000000
|
||||||
|
Midpoint: 91.004028320 err=1.004028320
|
||||||
|
Trapezoid: 87.991584778 err=2.008415222
|
||||||
|
Simpson: 89.999839783 err=0.000160217
|
||||||
|
|
||||||
|
-9x^2+3x-100 on [12.000000, 15.000000], n=2
|
||||||
|
Exact: -5119.500000000
|
||||||
|
Midpoint: -5114.437500000 err=5.062500000
|
||||||
|
Trapezoid: -5129.625000000 err=10.125000000
|
||||||
|
Simpson: -5119.500000000 err=0.000000000
|
||||||
|
|
||||||
|
6x^2-10x on [-50.000000, -5.000000], n=6
|
||||||
|
Exact: 262125.000000000
|
||||||
|
Midpoint: 260859.375000000 err=1265.625000000
|
||||||
|
Trapezoid: 264656.250000000 err=2531.250000000
|
||||||
|
Simpson: 262125.000000000 err=0.000000000
|
||||||
|
#+end_results
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* Bibliography
|
||||||
|
#+CITE_EXPORT: csl ./ieee.csl
|
||||||
|
#+print_bibliography:
|
||||||
BIN
documentation.pdf
Normal file
BIN
documentation.pdf
Normal file
Binary file not shown.
501
documentation.tex
Normal file
501
documentation.tex
Normal file
@@ -0,0 +1,501 @@
|
|||||||
|
% Created 2026-01-27 Di 15:08
|
||||||
|
% Intended LaTeX compiler: pdflatex
|
||||||
|
\documentclass[11pt]{article}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{longtable}
|
||||||
|
\usepackage{wrapfig}
|
||||||
|
\usepackage{rotating}
|
||||||
|
\usepackage[normalem]{ulem}
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\usepackage{amssymb}
|
||||||
|
\usepackage{capt-of}
|
||||||
|
\usepackage{hyperref}
|
||||||
|
\let\oldsection\section
|
||||||
|
\renewcommand{\section}{\clearpage\oldsection}
|
||||||
|
\let\oldsubsection\subsection
|
||||||
|
\renewcommand{\subsection}{\clearpage\oldsubsection}
|
||||||
|
\author{Mia Kronner Matr. 22201686}
|
||||||
|
\date{\today}
|
||||||
|
\title{Documentation for AutoSW Topic 5: Numerical integration methods}
|
||||||
|
\hypersetup{
|
||||||
|
pdfauthor={Mia Kronner Matr. 22201686},
|
||||||
|
pdftitle={Documentation for AutoSW Topic 5: Numerical integration methods},
|
||||||
|
pdfkeywords={},
|
||||||
|
pdfsubject={},
|
||||||
|
pdfcreator={Emacs 30.2 (Org mode 9.7.34)},
|
||||||
|
pdflang={English}}
|
||||||
|
\usepackage{calc}
|
||||||
|
\newlength{\cslhangindent}
|
||||||
|
\setlength{\cslhangindent}{1.5em}
|
||||||
|
\newlength{\csllabelsep}
|
||||||
|
\setlength{\csllabelsep}{0.6em}
|
||||||
|
\newlength{\csllabelwidth}
|
||||||
|
\setlength{\csllabelwidth}{0.45em * 3}
|
||||||
|
\newenvironment{cslbibliography}[2] % 1st arg. is hanging-indent, 2nd entry spacing.
|
||||||
|
{% By default, paragraphs are not indented.
|
||||||
|
\setlength{\parindent}{0pt}
|
||||||
|
% Hanging indent is turned on when first argument is 1.
|
||||||
|
\ifodd #1
|
||||||
|
\let\oldpar\par
|
||||||
|
\def\par{\hangindent=\cslhangindent\oldpar}
|
||||||
|
\fi
|
||||||
|
% Set entry spacing based on the second argument.
|
||||||
|
\setlength{\parskip}{\parskip + #2\baselineskip}
|
||||||
|
}%
|
||||||
|
{}
|
||||||
|
\newcommand{\cslblock}[1]{#1\hfill\break}
|
||||||
|
\newcommand{\cslleftmargin}[1]{\parbox[t]{\csllabelsep + \csllabelwidth}{#1}}
|
||||||
|
\newcommand{\cslrightinline}[1]
|
||||||
|
{\parbox[t]{\linewidth - \csllabelsep - \csllabelwidth}{#1}\break}
|
||||||
|
\newcommand{\cslindent}[1]{\hspace{\cslhangindent}#1}
|
||||||
|
\newcommand{\cslbibitem}[2]
|
||||||
|
{\leavevmode\vadjust pre{\hypertarget{citeproc_bib_item_#1}{}}#2}
|
||||||
|
\makeatletter
|
||||||
|
\newcommand{\cslcitation}[2]
|
||||||
|
{\protect\hyper@linkstart{cite}{citeproc_bib_item_#1}#2\hyper@linkend}
|
||||||
|
\makeatother\begin{document}
|
||||||
|
|
||||||
|
\maketitle
|
||||||
|
\tableofcontents
|
||||||
|
|
||||||
|
\section{Declaration of self reliance}
|
||||||
|
\label{sec:orgf1c5ba4}
|
||||||
|
I hereby declare that I have written this thesis independently in accordance with § 35 para. 7 RaPO (Framework Examination Regulations for Universities of Applied Sciences in Bavaria, BayRS 2210-4-1-4-1-WFK), have not submitted it elsewhere for examination purposes, have not used any sources or aids other than those indicated, and have marked all direct and indirect quotations as such.
|
||||||
|
\section{Graphical representation of the software design}
|
||||||
|
\label{sec:orgf50f0e3}
|
||||||
|
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=.9\linewidth]{./graphical-representation-white.drawio.png}
|
||||||
|
\end{center}
|
||||||
|
\section{Theoretical explanation of the relationships}
|
||||||
|
\label{sec:org15650c5}
|
||||||
|
\subsection{\texttt{"integrate.h"}:}
|
||||||
|
\label{sec:orgc09841a}
|
||||||
|
Interface for \texttt{integrate.c} Module.
|
||||||
|
Here is declared:
|
||||||
|
\begin{itemize}
|
||||||
|
\item a void float function pointer for the mathematical function which is to be integrated \texttt{integrand\_f}.
|
||||||
|
\item a typedef which contains the possible return values for the three integration functions \texttt{integ\_status\_t}
|
||||||
|
\item the three integration functions \texttt{midpoint} (rectangle midpoint method), \texttt{trapezoid} (trapezoid method), and \texttt{simpson} (simpson 1/3 method)
|
||||||
|
\begin{itemize}
|
||||||
|
\item they each take a integrand function \texttt{integrand\_f f}, its context as a void pointer \texttt{void *ctx}, the limits \texttt{a} and \texttt{b} and the number of intevals \texttt{n}
|
||||||
|
\end{itemize}
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
#ifndef INTEGRATE_H_
|
||||||
|
#define INTEGRATE_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef float (*integrand_f)(float x, void *ctx);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
INTEG_OK = 0,
|
||||||
|
INTEG_ERR_BAD_ARGS = -1,
|
||||||
|
INTEG_ERR_N_EVEN_REQUIRED = -2
|
||||||
|
} integ_status_t;
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
#endif // INTEGRATE_H_
|
||||||
|
\end{verbatim}
|
||||||
|
\subsection{\texttt{"integrate.c"}:}
|
||||||
|
\label{sec:orgbe94578}
|
||||||
|
Implements the three numerical integration algorithms (midpoint/rectangle, trapezoid, Simpson 1/3) behind the public interface from \texttt{integrate.h}, including argument validation and method-specific constraints.
|
||||||
|
|
||||||
|
The file includes \texttt{integrate.h} and provides the concrete implementations of \texttt{midpoint()}, \texttt{trapezoid()}, and \texttt{simpson()}, each computing an approximation of $$I = \int_a^bf(x)dx$$ by sampling the integrand at specific points and summing weighted contributions.
|
||||||
|
|
||||||
|
All three functions follow the same reusable calling convention: function pointer \texttt{integrand\_f f}, a generic context pointer \texttt{ctx}, integration bounds \texttt{a}, \texttt{b}, subinterval count \texttt{n}, and output pointer \texttt{out}.
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
|
||||||
|
static inline int bad_args(integrand_f f, float *a, float *b, unsigned *n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
return (f == NULL || out == NULL || *n == 0u || !(*b > *a));
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
|
||||||
|
float sum = 0.0f;
|
||||||
|
float fx = 0.0f;
|
||||||
|
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float x = a + 0.5f * h;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
fx = f(x, ctx);
|
||||||
|
sum = sum + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float sum = 0.5f * (f(a, ctx) + f(b, ctx));
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
sum = sum + f(x, ctx);
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
if (n & 1u) /*n must be even*/
|
||||||
|
{
|
||||||
|
return INTEG_ERR_N_EVEN_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sum_odd = 0.0f;
|
||||||
|
float sum_even = 0.0f;
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
const float fx = f(x, ctx);
|
||||||
|
if (i & 1u)
|
||||||
|
sum_odd = sum_odd + fx;
|
||||||
|
else
|
||||||
|
sum_even = sum_even + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out =
|
||||||
|
(h / 3.0f) * (f(a, ctx) + 4.0f * sum_odd + 2.0f * sum_even + f(b, ctx));
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
\end{verbatim}
|
||||||
|
\subsubsection{Common argument checking (\texttt{bad\_args})}
|
||||||
|
\label{sec:org5576bb4}
|
||||||
|
|
||||||
|
A shared internal helper \texttt{bad\_args()} is implemented as \texttt{static inline} to reduce call overhead and to allow the compiler to inline it for performance on embedded targets.
|
||||||
|
|
||||||
|
It returns an error condition if \texttt{f == NULL, out == NULL, n == 0} or the interval is invalid (the code checks \texttt{b > a}).
|
||||||
|
If \texttt{bad\_args()} reports invalid inputs, each public integration function returns \texttt{INTEG\_ERR\_BAD\_ARGS} immediately.
|
||||||
|
\subsubsection{Midpoint / rectangle method (\texttt{midpoint})}
|
||||||
|
\label{sec:orgb278e27}
|
||||||
|
\begin{enumerate}
|
||||||
|
\item Mathematical idea
|
||||||
|
\label{sec:orgd41c3d4}
|
||||||
|
|
||||||
|
The interval [a,b] is split into n subintervals of equal width $$h=(b-a)/n$$, and each subinterval [xi,xi+1] is approximated by a rectangle whose height is the function value at the midpoint $$xi+h/2$$.
|
||||||
|
The Formula is as follows: \cslcitation{1}{[1]}
|
||||||
|
|
||||||
|
$$\approx h \sum_{i=1}^n f({x_{i-1}+x_i}/2)$$
|
||||||
|
\item Implementation details
|
||||||
|
\label{sec:orgebae471}
|
||||||
|
The code computes \texttt{h}, initializes the first midpoint \texttt{x = a + 0.5fh}, then loops exactly \texttt{n} times, accumulating \texttt{sum = sum + f(x, ctx)} and stepping \texttt{x = x + h}.
|
||||||
|
|
||||||
|
Finally, the result is written as \texttt{out = sum * h} and the function returns \texttt{INTEG\_OK}.
|
||||||
|
\end{enumerate}
|
||||||
|
\subsubsection{Trapezoid method (\texttt{trapezoid})}
|
||||||
|
\label{sec:orga8108f1}
|
||||||
|
\begin{enumerate}
|
||||||
|
\item Mathematical idea
|
||||||
|
\label{sec:org31aecc1}
|
||||||
|
|
||||||
|
Each subinterval is approximated by a trapezoid formed by the points $$(xi,f(xi))$$ and $$(xi+1,f(xi+1))$$, giving the composite trapezoid rule.
|
||||||
|
|
||||||
|
This corresponds to the standard weighted sum \cslcitation{2}{[2]}
|
||||||
|
$$ = h/2 (f(x_0)+2f(x_1)+\dots+2f(x_{n-1})+f(x_n))$$
|
||||||
|
\item Implementation details
|
||||||
|
\label{sec:org36dc554}
|
||||||
|
|
||||||
|
The code computes \texttt{h}, then initializes \texttt{sum = 0.5f*(f(a,ctx)+f(b,ctx))} to apply the half-weight to the endpoints.
|
||||||
|
It iterates from the first interior node \texttt{x = a + h} for \texttt{i = 1..n-1}, adds each interior sample once (\texttt{sum = sum + f(x,ctx)}), then scales by \texttt{h} via \texttt{*out = sum * h}.
|
||||||
|
\end{enumerate}
|
||||||
|
\subsubsection{Simpson 1/3 method (\texttt{simpson})}
|
||||||
|
\label{sec:org6457a29}
|
||||||
|
\begin{enumerate}
|
||||||
|
\item Mathematical idea
|
||||||
|
\label{sec:orgd9bfe20}
|
||||||
|
|
||||||
|
Simpson's 1/3 rule approximates the function by piecewise quadratic polynomials over pairs of subintervals, which leads to alternating weights 4 and 2 for interior points.
|
||||||
|
|
||||||
|
The composite Simpson rule requires an even number of subintervals nn so that the domain can be grouped into $$n/2$$ pairs.
|
||||||
|
The formula is as such: \cslcitation{3}{[3]}
|
||||||
|
$$ \approx (h/3) [f(x_0)+4f(x_1)+2f(x_2)+ \dots 2f(x_{n-2})+4f(x_{n-1})+f(x_n)]$$
|
||||||
|
\item Implementation details and constraint handling
|
||||||
|
\label{sec:org4ce84b4}
|
||||||
|
|
||||||
|
After basic argument validation, the function checks \texttt{if (n \& 1u)} and returns \texttt{INTEG\_ERR\_N\_EVEN\_REQUIRED} if \texttt{n} is odd, enforcing the ``even n'' requirement from the interface contract.
|
||||||
|
|
||||||
|
It then loops over the interior nodes \texttt{i=1..n-1} and accumulates two partial sums: \texttt{sum\_odd} for odd indices (weight 4) and \texttt{sum\_even} for even indices (weight 2).
|
||||||
|
The final formula implemented is \\
|
||||||
|
\texttt{out = (h/3)(f(a)+4*sum\_odd+2*sum\_even+f(b))}, which matches the documented Simpson weighting scheme.
|
||||||
|
\end{enumerate}
|
||||||
|
\subsection{Performance-oriented aspects (embedded focus)}
|
||||||
|
\label{sec:org5f114cd}
|
||||||
|
|
||||||
|
The design avoids dynamic allocation and uses a caller-provided output pointer (\texttt{float *out}), which is predictable and typical for embedded C modules.
|
||||||
|
|
||||||
|
The \texttt{ctx} pointer allows passing coefficients/parameters without global variables, enabling reuse for many function types while keeping the integrator code generic.
|
||||||
|
Using \texttt{static inline} for \texttt{bad\_args} and keeping loop bodies simple (incrementing \texttt{x} by \texttt{h} rather than recomputing from scratch) supports compiler optimization and reduces runtime overhead.
|
||||||
|
|
||||||
|
When checking for evenness of \texttt{n} the simpson function uses \texttt{\& u1} instead of \texttt{\% 2}. It is not possible to substitue a \texttt{/2} for a \texttt{>{}>{}1} for the float variable type. Such tricks can not have been used for any values with the float type.
|
||||||
|
\section{Documentation of the reference examples used for testing}
|
||||||
|
\label{sec:org2d1f7ee}
|
||||||
|
\texttt{"main.c"} is a small command-line test application that demonstrates how to use the reusable integration module by defining example integrand functions, calling all three numerical methods, and printing absolute errors against known exact results.
|
||||||
|
|
||||||
|
The application includes \texttt{integrate.h} and uses standard library functionality (printing and absolute error via \texttt{fabsf}) to compare the numeric results to a known reference (``exact'') value.
|
||||||
|
Its purpose is not to be a generic framework, but a compact test harness that exercises the module API and makes method limitations visible at runtime (e.g., Simpson's even-\texttt{n} requirement).
|
||||||
|
\subsection{Test integrand design}
|
||||||
|
\label{sec:org3cbabb2}
|
||||||
|
Parameterized quadratic via context pointer
|
||||||
|
|
||||||
|
A small struct \texttt{quad\_t} stores coefficients \texttt{a2}, \texttt{a1}, \texttt{a0} for a quadratic polynomial $$f(x)=a_2x^2+a_1x+a_0$$, showing how the integrator's \texttt{void *ctx} can carry user-defined parameters without globals.
|
||||||
|
The function \texttt{f\_quad(float x, void ctx)} casts \texttt{ctx} to \texttt{const quad\_t} and evaluates the polynomial, matching the generic \texttt{integrand\_f} interface expected by the integration module.
|
||||||
|
\subsection{Test runner (\texttt{run\_one})}
|
||||||
|
\label{sec:org010d856}
|
||||||
|
|
||||||
|
The helper \texttt{run\_one(...)} calls \texttt{midpoint}, \texttt{trapezoid}, and \texttt{simpson} with the same function, bounds, and number of subintervals, storing results into three local floats (\texttt{r}, \texttt{t}, \texttt{s}).
|
||||||
|
It prints the integration problem setup (function name, bounds, \texttt{n}), prints the exact reference value, and prints each method's absolute error using \texttt{fabsf(result - exact)} for a direct precision comparison.
|
||||||
|
Simpson's status return is checked: if \texttt{simpson} returns \texttt{INTEG\_OK}, the Simpson result/error is printed, otherwise a message is printed indicating it was not computed because \texttt{n} must be even.
|
||||||
|
\subsection{Reference examples in \texttt{main()}}
|
||||||
|
\label{sec:orgd2d9b7a}
|
||||||
|
|
||||||
|
Four concrete test cases are instantiated using \texttt{quad\_t} coefficients and passed to \texttt{run\_one}.
|
||||||
|
They have been chosen in such a way that many edge cases are accounted for.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Example 1: \texttt{q} $$f(x)=x^2$$ on [0,1] with exact integral 1/3 and \texttt{n=10}
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=.9\linewidth]{./q.png}
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Example 2: \texttt{q2} $$f(x)=-x2+3x+50$$ on [-3,15] with exact integral 90 and \texttt{n=22}
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=.9\linewidth]{./q2.png}
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Example 3: \texttt{q3} $$f(x)=-9x^2+3x-100$$ on [12,15] with exact integral -5119.5 and \texttt{n=2}
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=.9\linewidth]{./q3.png}
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Example 4: \texttt{q4} $$f(x)=6x^2-10x$$ on [-50,-5] with exact integral 262125 and \texttt{n=6u}
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=.9\linewidth]{./q4.png}
|
||||||
|
\end{center}
|
||||||
|
\begin{verbatim}
|
||||||
|
#ifndef INTEGRATE_H_
|
||||||
|
#define INTEGRATE_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef float (*integrand_f)(float x, void *ctx);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
INTEG_OK = 0,
|
||||||
|
INTEG_ERR_BAD_ARGS = -1,
|
||||||
|
INTEG_ERR_N_EVEN_REQUIRED = -2
|
||||||
|
} integ_status_t;
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
#endif // INTEGRATE_H_
|
||||||
|
|
||||||
|
static inline int bad_args(integrand_f f, float *a, float *b, unsigned *n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
return (f == NULL || out == NULL || *n == 0u || !(*b > *a));
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
|
||||||
|
float sum = 0.0f;
|
||||||
|
float fx = 0.0f;
|
||||||
|
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float x = a + 0.5f * h;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
fx = f(x, ctx);
|
||||||
|
sum = sum + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float sum = 0.5f * (f(a, ctx) + f(b, ctx));
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
sum = sum + f(x, ctx);
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
if (n & 1u) /*n must be even*/
|
||||||
|
{
|
||||||
|
return INTEG_ERR_N_EVEN_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sum_odd = 0.0f;
|
||||||
|
float sum_even = 0.0f;
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
const float fx = f(x, ctx);
|
||||||
|
if (i & 1u)
|
||||||
|
sum_odd = sum_odd + fx;
|
||||||
|
else
|
||||||
|
sum_even = sum_even + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out =
|
||||||
|
(h / 3.0f) * (f(a, ctx) + 4.0f * sum_odd + 2.0f * sum_even + f(b, ctx));
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
float a2, a1, a0;
|
||||||
|
} quad_t;
|
||||||
|
|
||||||
|
static float f_quad(float x, void *ctx)
|
||||||
|
{
|
||||||
|
const quad_t *q = (const quad_t *)ctx;
|
||||||
|
return (q->a2 * x * x) + (q->a1 * x) + q->a0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_one(const char *name, integrand_f f, void *ctx, float a,
|
||||||
|
float b, float exact, unsigned n)
|
||||||
|
{
|
||||||
|
float r = 0.0f, t = 0.0f, s = 0.0f;
|
||||||
|
integ_status_t stS;
|
||||||
|
|
||||||
|
midpoint(f, ctx, a, b, n, &r);
|
||||||
|
trapezoid(f, ctx, a, b, n, &t);
|
||||||
|
|
||||||
|
stS = simpson(f, ctx, a, b, n, &s);
|
||||||
|
|
||||||
|
printf("\n%s on [%.6f, %.6f], n=%u\n", name, a, b, n);
|
||||||
|
printf("Exact: %.9f\n", exact);
|
||||||
|
printf("Midpoint: %.9f err=%.9f\n", r, fabsf(r - exact));
|
||||||
|
printf("Trapezoid: %.9f err=%.9f\n", t, fabsf(t - exact));
|
||||||
|
if (stS == INTEG_OK)
|
||||||
|
printf("Simpson: %.9f err=%.9f\n", s, fabsf(s - exact));
|
||||||
|
else
|
||||||
|
printf("Simpson: not computed (n must be even)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const quad_t q = {1.0f, 0.0f, 0.0f}; /*x^2*/
|
||||||
|
|
||||||
|
const quad_t q2 = {-1.0f, 3.0f, 50.0f}; /*x^2+3x+50*/
|
||||||
|
|
||||||
|
const quad_t q3 = {-9.0f, 3.0f, -100.0f}; /*-9x^2+3x-100*/
|
||||||
|
|
||||||
|
const quad_t q4 = {6.0f, -10.0f, 0.0f}; /*6x^2-10x*/
|
||||||
|
|
||||||
|
run_one("x^2", f_quad, (void *)&q, 0.0f, 1.0f, 1.0f / 3.0f, 10u);
|
||||||
|
|
||||||
|
run_one("x^2+3x+50", f_quad, (void *)&q2, -3.0f, 15.0f, 90.0f, 22u);
|
||||||
|
|
||||||
|
run_one("-9x^2+3x-100", f_quad, (void *)&q3, 12.0f, 15.0f, -5119.5f, 2u);
|
||||||
|
|
||||||
|
run_one("6x^2-10x", f_quad, (void *)&q4, -50.0f, -5.0f, 262125.0f, 6u);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
\end{verbatim}
|
||||||
|
\subsubsection{Results}
|
||||||
|
\label{sec:org8a0d097}
|
||||||
|
\section{Bibliography}
|
||||||
|
\label{sec:org8cd8f85}
|
||||||
|
\begin{cslbibliography}{0}{0}
|
||||||
|
\cslbibitem{1}{\cslleftmargin{[1]}\cslrightinline{“Engineering at Alberta Courses Rectangle Method,” Jan. 2026. Available: \url{https://engcourses-uofa.ca/books/numericalanalysis/numerical-integration/rectangle-method}}}
|
||||||
|
|
||||||
|
\cslbibitem{2}{\cslleftmargin{[2]}\cslrightinline{“Engineering at Alberta Courses Trapezoidal Rule,” Jan. 2026. Available: \url{https://engcourses-uofa.ca/books/numericalanalysis/numerical-integration/trapezoidal-rule}}}
|
||||||
|
|
||||||
|
\cslbibitem{3}{\cslleftmargin{[3]}\cslrightinline{“Simpson’s Rule (Simpson’s 1/3 Rule) - Formula, Derivation, Examples,” Jan. 2026. Available: \url{https://www.cuemath.com/simpsons-rule-formula}}}
|
||||||
|
|
||||||
|
\end{cslbibliography}
|
||||||
|
\end{document}
|
||||||
BIN
graphical-representation-black.drawio.png
Normal file
BIN
graphical-representation-black.drawio.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
BIN
graphical-representation-white.drawio.png
Normal file
BIN
graphical-representation-white.drawio.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
202
graphical-representation.drawio
Normal file
202
graphical-representation.drawio
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0" version="29.3.1">
|
||||||
|
<diagram name="Page-1" id="4ajKueOi00sYVpd6LPC8">
|
||||||
|
<mxGraphModel dx="1143" dy="690" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||||
|
<root>
|
||||||
|
<mxCell id="0" />
|
||||||
|
<mxCell id="1" parent="0" />
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-5" parent="1" style="swimlane;whiteSpace=wrap;html=1;" value=""integrate.h"" vertex="1">
|
||||||
|
<mxGeometry height="200" width="200" x="10" y="10" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-4" parent="MfzeZEFhQ-2HEEGgDQ4m-5" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="declaration of integrant function pointer" vertex="1">
|
||||||
|
<mxGeometry height="30" width="180" x="10" y="30" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-7" parent="MfzeZEFhQ-2HEEGgDQ4m-5" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>enum for function return values</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="180" x="10" y="60" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-8" parent="MfzeZEFhQ-2HEEGgDQ4m-5" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="deklaration function midpoint" vertex="1">
|
||||||
|
<mxGeometry height="30" width="170" x="20" y="90" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-9" parent="MfzeZEFhQ-2HEEGgDQ4m-5" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="deklaration function trapezoid" vertex="1">
|
||||||
|
<mxGeometry height="30" width="180" x="10" y="120" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-10" parent="MfzeZEFhQ-2HEEGgDQ4m-5" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="deklaration function simpson" vertex="1">
|
||||||
|
<mxGeometry height="30" width="180" x="10" y="150" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-11" parent="1" style="swimlane;whiteSpace=wrap;html=1;" value=""integrate.c"" vertex="1">
|
||||||
|
<mxGeometry height="180" width="330" x="10" y="260" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-12" parent="MfzeZEFhQ-2HEEGgDQ4m-11" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="function to check for missing arguments in function" vertex="1">
|
||||||
|
<mxGeometry height="30" width="280" x="20" y="40" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-14" parent="MfzeZEFhQ-2HEEGgDQ4m-11" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;rotation=0;" value="<div>midpoint rectangle integration method</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="210" x="60" y="70" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-15" parent="MfzeZEFhQ-2HEEGgDQ4m-11" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>trapez integration method</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="150" x="90" y="100" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-16" parent="MfzeZEFhQ-2HEEGgDQ4m-11" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>simpson 1/3 integration method</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="180" x="75" y="130" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-18" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-11" style="endArrow=none;html=1;rounded=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-5" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="270" y="440" as="sourcePoint" />
|
||||||
|
<mxPoint x="320" y="390" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-19" parent="1" style="swimlane;whiteSpace=wrap;html=1;" value="<div>"main.c"</div>" vertex="1">
|
||||||
|
<mxGeometry height="160" width="550" x="730" y="10" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-20" parent="MfzeZEFhQ-2HEEGgDQ4m-19" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="quad_t: typedef struct für berechnungs funktion (austauschbar)" vertex="1">
|
||||||
|
<mxGeometry height="30" width="530" x="10" y="30" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-21" parent="MfzeZEFhQ-2HEEGgDQ4m-19" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="f_quad: berechnungsfunktion für quadratische funktionen (ax^2+a1x+a0) (austauschbar)" vertex="1">
|
||||||
|
<mxGeometry height="30" width="530" x="10" y="60" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-22" parent="MfzeZEFhQ-2HEEGgDQ4m-19" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>run_one:&nbsp;funktion die testweise eine funktion in allen methoden integriert und ergebnisse ausgibt</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="530" x="10" y="90" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-23" parent="MfzeZEFhQ-2HEEGgDQ4m-19" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>main: führt run_one für 4 beispielfunktionen aus</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="260" x="145" y="120" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-32" edge="1" parent="MfzeZEFhQ-2HEEGgDQ4m-19" source="MfzeZEFhQ-2HEEGgDQ4m-23" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-22" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="110" y="140" as="sourcePoint" />
|
||||||
|
<mxPoint x="-50" y="250" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-24" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-28" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-8" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="730" y="120" as="sourcePoint" />
|
||||||
|
<mxPoint x="610" y="220" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-26" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-28" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-9" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="700" y="150" as="sourcePoint" />
|
||||||
|
<mxPoint x="780" y="390" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-27" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-28" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-10" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="570" y="340" as="sourcePoint" />
|
||||||
|
<mxPoint x="620" y="290" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-29" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-22" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="123" as="sourcePoint" />
|
||||||
|
<mxPoint x="200" y="145" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-30" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-22" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="123" as="sourcePoint" />
|
||||||
|
<mxPoint x="200" y="115" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-31" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-22" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="123" as="sourcePoint" />
|
||||||
|
<mxPoint x="200" y="175" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-28" parent="1" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>gibt pointer f_quad über</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="210" x="410" y="100" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-33" edge="1" parent="1" style="endArrow=classic;html=1;rounded=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="280" y="340" as="sourcePoint" />
|
||||||
|
<mxPoint x="550" y="70" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-35" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-16" style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.25;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="650" y="370" as="sourcePoint" />
|
||||||
|
<mxPoint x="700" y="320" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-36" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-15" style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.25;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-28" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="510" y="330" as="sourcePoint" />
|
||||||
|
<mxPoint x="540" y="240" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-37" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-28" style="endArrow=classic;html=1;rounded=0;exitX=0.75;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-21" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="520" y="100" as="sourcePoint" />
|
||||||
|
<mxPoint x="570" y="50" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-38" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-42" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-14" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="630" y="310" as="sourcePoint" />
|
||||||
|
<mxPoint x="280" y="340" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-39" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-42" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-15" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="480" y="400" as="sourcePoint" />
|
||||||
|
<mxPoint x="530" y="350" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-40" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-42" style="endArrow=classic;html=1;rounded=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-16" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="90" as="sourcePoint" />
|
||||||
|
<mxPoint x="300" y="490" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-41" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-21" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-42" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="93" as="sourcePoint" />
|
||||||
|
<mxPoint x="250" y="383" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-43" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-21" style="endArrow=classic;html=1;rounded=0;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-42" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="93" as="sourcePoint" />
|
||||||
|
<mxPoint x="280" y="353" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-44" edge="1" parent="1" style="endArrow=classic;html=1;rounded=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-42" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="740" y="90" as="sourcePoint" />
|
||||||
|
<mxPoint x="265" y="413" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-42" parent="1" style="text;html=1;whiteSpace=wrap;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;rounded=0;" value="<div>gibt ergebnis von f_quad zurück</div>" vertex="1">
|
||||||
|
<mxGeometry height="30" width="110" x="410" y="260" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-52" edge="1" parent="1" style="curved=1;endArrow=classic;html=1;rounded=0;" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<Array as="points" />
|
||||||
|
<mxPoint x="290" y="350" as="sourcePoint" />
|
||||||
|
<mxPoint x="475" y="358" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-53" edge="1" parent="1" source="MfzeZEFhQ-2HEEGgDQ4m-15" style="curved=1;endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;exitX=1;exitY=1;exitDx=0;exitDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-51" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<Array as="points" />
|
||||||
|
<mxPoint x="250" y="390" as="sourcePoint" />
|
||||||
|
<mxPoint x="740" y="130" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-54" edge="1" parent="1" style="curved=1;endArrow=classic;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-51" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<Array as="points" />
|
||||||
|
<mxPoint x="270" y="420" as="sourcePoint" />
|
||||||
|
<mxPoint x="740" y="130" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-51" parent="1" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;" value="<div>Endergebnis</div><div>float *out</div>" vertex="1">
|
||||||
|
<mxGeometry height="40" width="80" x="475" y="350" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="MfzeZEFhQ-2HEEGgDQ4m-56" edge="1" parent="1" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=1;entryDx=0;entryDy=0;" target="MfzeZEFhQ-2HEEGgDQ4m-22" value="">
|
||||||
|
<mxGeometry height="50" relative="1" width="50" as="geometry">
|
||||||
|
<mxPoint x="550" y="360" as="sourcePoint" />
|
||||||
|
<mxPoint x="600" y="310" as="targetPoint" />
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
</root>
|
||||||
|
</mxGraphModel>
|
||||||
|
</diagram>
|
||||||
|
</mxfile>
|
||||||
519
ieee.csl
Normal file
519
ieee.csl
Normal file
@@ -0,0 +1,519 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only">
|
||||||
|
<info>
|
||||||
|
<title>IEEE Reference Guide version 11.29.2023</title>
|
||||||
|
<title-short>Institute of Electrical and Electronics Engineers</title-short>
|
||||||
|
<id>http://www.zotero.org/styles/ieee</id>
|
||||||
|
<link href="http://www.zotero.org/styles/ieee" rel="self"/>
|
||||||
|
<link href="https://journals.ieeeauthorcenter.ieee.org/your-role-in-article-production/ieee-editorial-style-manual/" rel="documentation"/>
|
||||||
|
<author>
|
||||||
|
<name>Michael Berkowitz</name>
|
||||||
|
<email>mberkowi@gmu.edu</email>
|
||||||
|
</author>
|
||||||
|
<contributor>
|
||||||
|
<name>Julian Onions</name>
|
||||||
|
<email>julian.onions@gmail.com</email>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Rintze Zelle</name>
|
||||||
|
<uri>http://twitter.com/rintzezelle</uri>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Stephen Frank</name>
|
||||||
|
<uri>http://www.zotero.org/sfrank</uri>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Sebastian Karcher</name>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Giuseppe Silano</name>
|
||||||
|
<email>g.silano89@gmail.com</email>
|
||||||
|
<uri>http://giuseppesilano.net</uri>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Patrick O'Brien</name>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Brenton M. Wiernik</name>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Oliver Couch</name>
|
||||||
|
<email>oliver.couch@gmail.com</email>
|
||||||
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Andrew Dunning</name>
|
||||||
|
<uri>https://orcid.org/0000-0003-0464-5036</uri>
|
||||||
|
</contributor>
|
||||||
|
<category citation-format="numeric"/>
|
||||||
|
<category field="engineering"/>
|
||||||
|
<category field="generic-base"/>
|
||||||
|
<summary>IEEE style as per the 2023 guidelines.</summary>
|
||||||
|
<updated>2024-03-27T11:41:27+00:00</updated>
|
||||||
|
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
|
||||||
|
</info>
|
||||||
|
<locale xml:lang="en">
|
||||||
|
<date form="text">
|
||||||
|
<date-part name="month" form="short" suffix=" "/>
|
||||||
|
<date-part name="day" form="numeric-leading-zeros" suffix=", "/>
|
||||||
|
<date-part name="year"/>
|
||||||
|
</date>
|
||||||
|
<terms>
|
||||||
|
<term name="chapter" form="short">ch.</term>
|
||||||
|
<term name="chapter-number" form="short">ch.</term>
|
||||||
|
<term name="presented at">presented at the</term>
|
||||||
|
<term name="available at">available</term>
|
||||||
|
<!-- always use three-letter abbreviations for months -->
|
||||||
|
<term name="month-06" form="short">Jun.</term>
|
||||||
|
<term name="month-07" form="short">Jul.</term>
|
||||||
|
<term name="month-09" form="short">Sep.</term>
|
||||||
|
</terms>
|
||||||
|
</locale>
|
||||||
|
<!-- Macros -->
|
||||||
|
<macro name="status">
|
||||||
|
<choose>
|
||||||
|
<if variable="page issue volume" match="none">
|
||||||
|
<text variable="status" text-case="capitalize-first" suffix="" font-weight="bold"/>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="edition">
|
||||||
|
<choose>
|
||||||
|
<if type="bill book chapter graphic legal_case legislation motion_picture paper-conference report song" match="any">
|
||||||
|
<choose>
|
||||||
|
<if is-numeric="edition">
|
||||||
|
<group delimiter=" ">
|
||||||
|
<number variable="edition" form="ordinal"/>
|
||||||
|
<text term="edition" form="short"/>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<text variable="edition" text-case="capitalize-first" suffix="."/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="issued">
|
||||||
|
<choose>
|
||||||
|
<if type="article-journal report" match="any">
|
||||||
|
<date variable="issued">
|
||||||
|
<date-part name="month" form="short" suffix=" "/>
|
||||||
|
<date-part name="year" form="long"/>
|
||||||
|
</date>
|
||||||
|
</if>
|
||||||
|
<else-if type="bill book chapter graphic legal_case legislation song thesis" match="any">
|
||||||
|
<date variable="issued">
|
||||||
|
<date-part name="year" form="long"/>
|
||||||
|
</date>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="paper-conference" match="any">
|
||||||
|
<date variable="issued">
|
||||||
|
<date-part name="month" form="short"/>
|
||||||
|
<date-part name="year" prefix=" "/>
|
||||||
|
</date>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="motion_picture" match="any">
|
||||||
|
<date variable="issued" form="text" prefix="(" suffix=")"/>
|
||||||
|
</else-if>
|
||||||
|
<else>
|
||||||
|
<date variable="issued" form="text"/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="author">
|
||||||
|
<names variable="author">
|
||||||
|
<name and="text" et-al-min="7" et-al-use-first="1" initialize-with=". "/>
|
||||||
|
<label form="short" prefix=", " text-case="capitalize-first"/>
|
||||||
|
<et-al font-style="italic"/>
|
||||||
|
<substitute>
|
||||||
|
<names variable="editor"/>
|
||||||
|
<names variable="translator"/>
|
||||||
|
<text macro="director"/>
|
||||||
|
</substitute>
|
||||||
|
</names>
|
||||||
|
</macro>
|
||||||
|
<macro name="editor">
|
||||||
|
<names variable="editor">
|
||||||
|
<name initialize-with=". " delimiter=", " and="text"/>
|
||||||
|
<label form="short" prefix=", " text-case="capitalize-first"/>
|
||||||
|
</names>
|
||||||
|
</macro>
|
||||||
|
<macro name="director">
|
||||||
|
<names variable="director">
|
||||||
|
<name and="text" et-al-min="7" et-al-use-first="1" initialize-with=". "/>
|
||||||
|
<et-al font-style="italic"/>
|
||||||
|
</names>
|
||||||
|
</macro>
|
||||||
|
<macro name="locators">
|
||||||
|
<group delimiter=", ">
|
||||||
|
<text macro="edition"/>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text term="volume" form="short"/>
|
||||||
|
<number variable="volume" form="numeric"/>
|
||||||
|
</group>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<number variable="number-of-volumes" form="numeric"/>
|
||||||
|
<text term="volume" form="short" plural="true"/>
|
||||||
|
</group>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text term="issue" form="short"/>
|
||||||
|
<number variable="issue" form="numeric"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</macro>
|
||||||
|
<macro name="title">
|
||||||
|
<choose>
|
||||||
|
<if type="bill book graphic legal_case legislation motion_picture song standard software" match="any">
|
||||||
|
<text variable="title" font-style="italic"/>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<text variable="title" quotes="true"/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="publisher">
|
||||||
|
<choose>
|
||||||
|
<if type="bill book chapter graphic legal_case legislation motion_picture paper-conference song" match="any">
|
||||||
|
<group delimiter=": ">
|
||||||
|
<text variable="publisher-place"/>
|
||||||
|
<text variable="publisher"/>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<group delimiter=", ">
|
||||||
|
<text variable="publisher"/>
|
||||||
|
<text variable="publisher-place"/>
|
||||||
|
</group>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="event">
|
||||||
|
<choose>
|
||||||
|
<!-- Published Conference Paper -->
|
||||||
|
<if type="paper-conference speech" match="any">
|
||||||
|
<choose>
|
||||||
|
<if variable="container-title" match="any">
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text term="in"/>
|
||||||
|
<text variable="container-title" font-style="italic"/>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
<!-- Unpublished Conference Paper -->
|
||||||
|
<else>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text term="presented at"/>
|
||||||
|
<text variable="event"/>
|
||||||
|
</group>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="access">
|
||||||
|
<choose>
|
||||||
|
<if type="webpage post post-weblog" match="any">
|
||||||
|
<!-- https://url.com/ (accessed Mon. DD, YYYY). -->
|
||||||
|
<choose>
|
||||||
|
<if variable="URL">
|
||||||
|
<group delimiter=". " prefix=" ">
|
||||||
|
<group delimiter=": ">
|
||||||
|
<text term="accessed" text-case="capitalize-first"/>
|
||||||
|
<date variable="accessed" form="text"/>
|
||||||
|
</group>
|
||||||
|
<text term="online" prefix="[" suffix="]" text-case="capitalize-first"/>
|
||||||
|
<group delimiter=": ">
|
||||||
|
<text term="available at" text-case="capitalize-first"/>
|
||||||
|
<text variable="URL"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</if>
|
||||||
|
<else-if match="any" variable="DOI">
|
||||||
|
<!-- doi: 10.1000/xyz123. -->
|
||||||
|
<text variable="DOI" prefix=" doi: " suffix="."/>
|
||||||
|
</else-if>
|
||||||
|
<else-if variable="URL">
|
||||||
|
<!-- Accessed: Mon. DD, YYYY. [Medium]. Available: https://URL.com/ -->
|
||||||
|
<group delimiter=". " prefix=" " suffix=". ">
|
||||||
|
<!-- Accessed: Mon. DD, YYYY. -->
|
||||||
|
<group delimiter=": ">
|
||||||
|
<text term="accessed" text-case="capitalize-first"/>
|
||||||
|
<date variable="accessed" form="text"/>
|
||||||
|
</group>
|
||||||
|
<!-- [Online Video]. -->
|
||||||
|
<group prefix="[" suffix="]" delimiter=" ">
|
||||||
|
<choose>
|
||||||
|
<if variable="medium" match="any">
|
||||||
|
<text variable="medium" text-case="capitalize-first"/>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<text term="online" text-case="capitalize-first"/>
|
||||||
|
<choose>
|
||||||
|
<if type="motion_picture">
|
||||||
|
<text term="video" text-case="capitalize-first"/>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<!-- Available: https://URL.com/ -->
|
||||||
|
<group delimiter=": " prefix=" ">
|
||||||
|
<text term="available at" text-case="capitalize-first"/>
|
||||||
|
<text variable="URL"/>
|
||||||
|
</group>
|
||||||
|
</else-if>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="page">
|
||||||
|
<choose>
|
||||||
|
<if type="article-journal" variable="number" match="all">
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text value="Art."/>
|
||||||
|
<text term="issue" form="short"/>
|
||||||
|
<text variable="number"/>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<label variable="page" form="short"/>
|
||||||
|
<text variable="page"/>
|
||||||
|
</group>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<macro name="citation-locator">
|
||||||
|
<group delimiter=" ">
|
||||||
|
<choose>
|
||||||
|
<if locator="page">
|
||||||
|
<label variable="locator" form="short"/>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<label variable="locator" form="short" text-case="capitalize-first"/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
<text variable="locator"/>
|
||||||
|
</group>
|
||||||
|
</macro>
|
||||||
|
<macro name="geographic-location">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<choose>
|
||||||
|
<if variable="publisher-place">
|
||||||
|
<text variable="publisher-place" text-case="title"/>
|
||||||
|
</if>
|
||||||
|
<else-if variable="event-place">
|
||||||
|
<text variable="event-place" text-case="title"/>
|
||||||
|
</else-if>
|
||||||
|
</choose>
|
||||||
|
</group>
|
||||||
|
</macro>
|
||||||
|
<!-- Series -->
|
||||||
|
<macro name="collection">
|
||||||
|
<choose>
|
||||||
|
<if variable="collection-title" match="any">
|
||||||
|
<text term="in" suffix=" "/>
|
||||||
|
<group delimiter=", " suffix=". ">
|
||||||
|
<text variable="collection-title"/>
|
||||||
|
<text variable="collection-number" prefix="no. "/>
|
||||||
|
<text variable="volume" prefix="vol. "/>
|
||||||
|
</group>
|
||||||
|
</if>
|
||||||
|
</choose>
|
||||||
|
</macro>
|
||||||
|
<!-- Citation -->
|
||||||
|
<citation>
|
||||||
|
<sort>
|
||||||
|
<key variable="citation-number"/>
|
||||||
|
</sort>
|
||||||
|
<layout delimiter=", ">
|
||||||
|
<group prefix="[" suffix="]" delimiter=", ">
|
||||||
|
<text variable="citation-number"/>
|
||||||
|
<text macro="citation-locator"/>
|
||||||
|
</group>
|
||||||
|
</layout>
|
||||||
|
</citation>
|
||||||
|
<!-- Bibliography -->
|
||||||
|
<bibliography entry-spacing="0" second-field-align="flush">
|
||||||
|
<layout>
|
||||||
|
<!-- Citation Number -->
|
||||||
|
<text variable="citation-number" prefix="[" suffix="]"/>
|
||||||
|
<!-- Author(s) -->
|
||||||
|
<text macro="author" suffix=", "/>
|
||||||
|
<!-- Rest of Citation -->
|
||||||
|
<choose>
|
||||||
|
<!-- Specific Formats -->
|
||||||
|
<if type="article-journal">
|
||||||
|
<group delimiter=", ">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="container-title" font-style="italic" form="short"/>
|
||||||
|
<text macro="locators"/>
|
||||||
|
<text macro="page"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
<text macro="status"/>
|
||||||
|
</group>
|
||||||
|
<choose>
|
||||||
|
<if variable="URL DOI" match="none">
|
||||||
|
<text value="."/>
|
||||||
|
</if>
|
||||||
|
<else>
|
||||||
|
<text value=","/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
<text macro="access"/>
|
||||||
|
</if>
|
||||||
|
<else-if type="paper-conference speech" match="any">
|
||||||
|
<group delimiter=", " suffix=", ">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="event"/>
|
||||||
|
<text macro="editor"/>
|
||||||
|
</group>
|
||||||
|
<text macro="collection"/>
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
<text macro="page"/>
|
||||||
|
<text macro="status"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="chapter">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text term="in" suffix=" "/>
|
||||||
|
<text variable="container-title" font-style="italic"/>
|
||||||
|
</group>
|
||||||
|
<text macro="locators"/>
|
||||||
|
<text macro="editor"/>
|
||||||
|
<text macro="collection"/>
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<label variable="chapter-number" form="short"/>
|
||||||
|
<text variable="chapter-number"/>
|
||||||
|
</group>
|
||||||
|
<text macro="page"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="report">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text variable="genre"/>
|
||||||
|
<text variable="number"/>
|
||||||
|
</group>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="thesis">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="genre"/>
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="software">
|
||||||
|
<group delimiter=". " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="issued" prefix="(" suffix=")"/>
|
||||||
|
<text variable="genre"/>
|
||||||
|
<text macro="publisher"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="article">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
<group delimiter=": ">
|
||||||
|
<text macro="publisher" font-style="italic"/>
|
||||||
|
<text variable="number"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="webpage post-weblog post" match="any">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="container-title"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="patent">
|
||||||
|
<group delimiter=", ">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="number"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<!-- Online Video -->
|
||||||
|
<else-if type="motion_picture">
|
||||||
|
<text macro="geographic-location" suffix=". "/>
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="standard">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<group delimiter=" ">
|
||||||
|
<text variable="genre"/>
|
||||||
|
<text variable="number"/>
|
||||||
|
</group>
|
||||||
|
<text macro="geographic-location"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<!-- Generic/Fallback Formats -->
|
||||||
|
<else-if type="bill book graphic legal_case legislation report song" match="any">
|
||||||
|
<group delimiter=", " suffix=". ">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text macro="locators"/>
|
||||||
|
</group>
|
||||||
|
<text macro="collection"/>
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
<text macro="page"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else-if type="article-magazine article-newspaper broadcast interview manuscript map patent personal_communication song speech thesis webpage" match="any">
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="container-title" font-style="italic"/>
|
||||||
|
<text macro="locators"/>
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="page"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else-if>
|
||||||
|
<else>
|
||||||
|
<group delimiter=", " suffix=". ">
|
||||||
|
<text macro="title"/>
|
||||||
|
<text variable="container-title" font-style="italic"/>
|
||||||
|
<text macro="locators"/>
|
||||||
|
</group>
|
||||||
|
<text macro="collection"/>
|
||||||
|
<group delimiter=", " suffix=".">
|
||||||
|
<text macro="publisher"/>
|
||||||
|
<text macro="page"/>
|
||||||
|
<text macro="issued"/>
|
||||||
|
</group>
|
||||||
|
<text macro="access"/>
|
||||||
|
</else>
|
||||||
|
</choose>
|
||||||
|
</layout>
|
||||||
|
</bibliography>
|
||||||
|
</style>
|
||||||
90
integrate.c
Normal file
90
integrate.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "integrate.h"
|
||||||
|
|
||||||
|
static inline int bad_args(integrand_f f, float *a, float *b, unsigned *n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
return (f == NULL || out == NULL || *n == 0u || !(*b > *a));
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
|
||||||
|
float sum = 0.0f;
|
||||||
|
float fx = 0.0f;
|
||||||
|
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float x = a + 0.5f * h;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
fx = f(x, ctx);
|
||||||
|
sum = sum + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
float sum = 0.5f * (f(a, ctx) + f(b, ctx));
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
sum = sum + f(x, ctx);
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = sum * h;
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out)
|
||||||
|
{
|
||||||
|
/*check if all necessary parameters have been given */
|
||||||
|
if (bad_args(f, &a, &b, &n, out))
|
||||||
|
{
|
||||||
|
return INTEG_ERR_BAD_ARGS;
|
||||||
|
}
|
||||||
|
if (n & 1u) /*n must be even*/
|
||||||
|
{
|
||||||
|
return INTEG_ERR_N_EVEN_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sum_odd = 0.0f;
|
||||||
|
float sum_even = 0.0f;
|
||||||
|
/*intervall width h: */
|
||||||
|
const float h = (b - a) / (float)n;
|
||||||
|
|
||||||
|
float x = a + h;
|
||||||
|
for (unsigned i = 1; i < n; ++i)
|
||||||
|
{
|
||||||
|
const float fx = f(x, ctx);
|
||||||
|
if (i & 1u)
|
||||||
|
sum_odd = sum_odd + fx;
|
||||||
|
else
|
||||||
|
sum_even = sum_even + fx;
|
||||||
|
x = x + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out =
|
||||||
|
(h / 3.0f) * (f(a, ctx) + 4.0f * sum_odd + 2.0f * sum_even + f(b, ctx));
|
||||||
|
return INTEG_OK;
|
||||||
|
}
|
||||||
24
integrate.h
Normal file
24
integrate.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef INTEGRATE_H_
|
||||||
|
#define INTEGRATE_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef float (*integrand_f)(float x, void *ctx);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
INTEG_OK = 0,
|
||||||
|
INTEG_ERR_BAD_ARGS = -1,
|
||||||
|
INTEG_ERR_N_EVEN_REQUIRED = -2
|
||||||
|
} integ_status_t;
|
||||||
|
|
||||||
|
integ_status_t midpoint(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t trapezoid(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
integ_status_t simpson(integrand_f f, void *ctx, float a, float b, unsigned n,
|
||||||
|
float *out);
|
||||||
|
|
||||||
|
#endif // INTEGRATE_H_
|
||||||
BIN
integrate.o
Normal file
BIN
integrate.o
Normal file
Binary file not shown.
56
main.c
Normal file
56
main.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "integrate.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
float a2, a1, a0;
|
||||||
|
} quad_t;
|
||||||
|
|
||||||
|
static float f_quad(float x, void *ctx)
|
||||||
|
{
|
||||||
|
const quad_t *q = (const quad_t *)ctx;
|
||||||
|
return (q->a2 * x * x) + (q->a1 * x) + q->a0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run_one(const char *name, integrand_f f, void *ctx, float a,
|
||||||
|
float b, float exact, unsigned n)
|
||||||
|
{
|
||||||
|
float r = 0.0f, t = 0.0f, s = 0.0f;
|
||||||
|
integ_status_t stS;
|
||||||
|
|
||||||
|
midpoint(f, ctx, a, b, n, &r);
|
||||||
|
trapezoid(f, ctx, a, b, n, &t);
|
||||||
|
|
||||||
|
stS = simpson(f, ctx, a, b, n, &s);
|
||||||
|
|
||||||
|
printf("\n%s on [%.6f, %.6f], n=%u\n", name, a, b, n);
|
||||||
|
printf("Exact: %.9f\n", exact);
|
||||||
|
printf("Midpoint: %.9f err=%.9f\n", r, fabsf(r - exact));
|
||||||
|
printf("Trapezoid: %.9f err=%.9f\n", t, fabsf(t - exact));
|
||||||
|
if (stS == INTEG_OK)
|
||||||
|
printf("Simpson: %.9f err=%.9f\n", s, fabsf(s - exact));
|
||||||
|
else
|
||||||
|
printf("Simpson: not computed (n must be even)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const quad_t q = {1.0f, 0.0f, 0.0f}; /*x^2*/
|
||||||
|
|
||||||
|
const quad_t q2 = {-1.0f, 3.0f, 50.0f}; /*x^2+3x+50*/
|
||||||
|
|
||||||
|
const quad_t q3 = {-9.0f, 3.0f, -100.0f}; /*-9x^2+3x-100*/
|
||||||
|
|
||||||
|
const quad_t q4 = {6.0f, -10.0f, 0.0f}; /*6x^2-10x*/
|
||||||
|
|
||||||
|
run_one("x^2", f_quad, (void *)&q, 0.0f, 1.0f, 1.0f / 3.0f, 10u);
|
||||||
|
|
||||||
|
run_one("x^2+3x+50", f_quad, (void *)&q2, -3.0f, 15.0f, 90.0f, 22u);
|
||||||
|
|
||||||
|
run_one("-9x^2+3x-100", f_quad, (void *)&q3, 12.0f, 15.0f, -5119.5f, 2u);
|
||||||
|
|
||||||
|
run_one("6x^2-10x", f_quad, (void *)&q4, -50.0f, -5.0f, 262125.0f, 6u);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
22
makefile
Normal file
22
makefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#Makefile
|
||||||
|
|
||||||
|
CC=gcc
|
||||||
|
CFLAGS=-g -fanalyzer
|
||||||
|
# CFLAGS= -fanalyzer
|
||||||
|
# LIBS=-lsodium -larchive
|
||||||
|
|
||||||
|
SRC_FILES=main.c integrate.c
|
||||||
|
OBJ_FILES=$(SRC_FILES:.c=.o)
|
||||||
|
|
||||||
|
TARGET=main
|
||||||
|
|
||||||
|
$(TARGET): $(OBJ_FILES)
|
||||||
|
$(CC) $(CFLAGS) $(OBJ_FILES) $(LIBS) -o $(TARGET)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJ_FILES)
|
||||||
|
# rm -f $(OBJ_FILES) $(TARGET)
|
||||||
407
notes.org
Normal file
407
notes.org
Normal file
@@ -0,0 +1,407 @@
|
|||||||
|
* PoP
|
||||||
|
| 1 | M | Fixed Point Arithmetic | Single Person | max 5x |
|
||||||
|
| 2 | | General fast exponentation according to Legendre / square root with Newton iteration | Single Person | max 3x |
|
||||||
|
| 3 | M | NVM Manager | 2 | max 3x |
|
||||||
|
| 4 | M | Multiport RAM Interface MPRAM-Interface | Single Person | max 3x |
|
||||||
|
| 5 | | Numerical integration methods | Single Person | max 3x |
|
||||||
|
with callback function, uses function pointer
|
||||||
|
was mit power of two is sufficient
|
||||||
|
| 6 | M | Djikstra algorithm | Single Person | max 5x |
|
||||||
|
5-7 nodes
|
||||||
|
| 8 | M | Online methods - Variance according to Welford and arithmetic mean | Single person | max 5x |
|
||||||
|
| 9 | | Message-based intertask communication | 2 | max 2x |
|
||||||
|
|
||||||
|
|
||||||
|
Numerical integration methods
|
||||||
|
|
||||||
|
Topic 5: Numerical integration methods
|
||||||
|
|
||||||
|
The aim of this task is to implement three variants of numerical approaches for calculating integrals
|
||||||
|
in a software module.
|
||||||
|
|
||||||
|
A function for the rectangle method, the trapezoid method, and the Simpson method should be designed and coded in a reusable module.
|
||||||
|
|
||||||
|
When defining the interface of the C functions, pay attention to reusability.
|
||||||
|
|
||||||
|
The task also includes developing a sample application to test the three variants. Select two examples of mathematical functions whose integrals are to be determined, with corresponding integration boundaries, and compare the three methods in terms of their precision. Test the limitations of the methods. Substantiate your results.
|
||||||
|
|
||||||
|
Explain the mathematical relationships underlying the methods in your paper. A graphical representation will help to illustrate the understanding of the relationships.
|
||||||
|
|
||||||
|
Optimize the source code as far as possible for performance-optimized use on an embedded controller.
|
||||||
|
|
||||||
|
The result of the task is a project that can be compiled with MS Studio, which enables the software module to be tested (suitable test cases, etc.) using a command line application, plus the documentation specified below.
|
||||||
|
|
||||||
|
Scope of relevant task-specific documentation
|
||||||
|
- Graphical representation of the software design and compact description of the key relationships (1 page)
|
||||||
|
- Theoretical explanation of the relationships (mathematical, algorithmic, etc.) that need to be taken into account here (2 pages)
|
||||||
|
- Documentation of the reference examples used for testing, with graphical representation and explanation of method limitations (2 pages)
|
||||||
|
|
||||||
|
|
||||||
|
** Notizen zu Folien
|
||||||
|
|
||||||
|
*** keine Unions
|
||||||
|
*** enum
|
||||||
|
|
||||||
|
Implizite Deklaration:
|
||||||
|
#+begin_src c
|
||||||
|
enum t_AlgoEnumVals{
|
||||||
|
INIT = 0u,
|
||||||
|
RUNNING = 1u,
|
||||||
|
WAITING = 2u,
|
||||||
|
INVALID = 3u
|
||||||
|
};
|
||||||
|
#+end_src
|
||||||
|
-> definiert nur den Typnamen enum t_AlgoEnumVals, reserviert aber keinen Speicher, solange keine Variable dieses Typs definiert wird.
|
||||||
|
|
||||||
|
Explizite Deklaration:
|
||||||
|
#+begin_src c
|
||||||
|
typedef enum{
|
||||||
|
INIT = 0u,
|
||||||
|
RUNNING = 1u,
|
||||||
|
WAITING = 2u,
|
||||||
|
INVALID = 3u
|
||||||
|
} t_AlgoEnumVals;
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
-> macht das Gleiche, nur dass der Typ danach über den Alias t_AlgoEnumVals ohne enum verwendet werden kann; auch hier entsteht Speicher erst bei Variablen/Objekten dieses Typs.
|
||||||
|
|
||||||
|
*** kombination union und struct
|
||||||
|
|
||||||
|
#+begin_src c
|
||||||
|
typedef unsigned char t_BYTE;
|
||||||
|
typedef unsigned short t_WORD;
|
||||||
|
typedef unsigned long t_DWORD;
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
t_BYTE Wert0;
|
||||||
|
t_BYTE Wert1;
|
||||||
|
t_BYTE Wert2;
|
||||||
|
t_WORD Wert3;
|
||||||
|
t_DWORD Wert4;
|
||||||
|
t_DWORD Wert5;
|
||||||
|
t_DWORD Wert6;
|
||||||
|
t_WORD Wert7;
|
||||||
|
t_BYTE Wert8;
|
||||||
|
}t_Struct;
|
||||||
|
|
||||||
|
typedef union{
|
||||||
|
t_BYTE vbyArray[20];
|
||||||
|
t_Struct stStruct;
|
||||||
|
}t_unStructUnion;
|
||||||
|
|
||||||
|
#pragma pack()
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
-> see 05 P9
|
||||||
|
|
||||||
|
*** Funktionsaufrufe
|
||||||
|
|
||||||
|
Call by Value:
|
||||||
|
#+begin_src c
|
||||||
|
int func1(int par1, int par2){
|
||||||
|
return(par1*par2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void){
|
||||||
|
int a = 0;
|
||||||
|
|
||||||
|
// function call by value:
|
||||||
|
a = func1(5,3);
|
||||||
|
|
||||||
|
printf("Result %d\n",a);
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
-> Werte werden über Stack direkt übergeben.
|
||||||
|
|
||||||
|
Call by Reference:
|
||||||
|
#+begin_src c
|
||||||
|
int func1(int par1, int par2){
|
||||||
|
*par1 = 5;
|
||||||
|
*par2 = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void){
|
||||||
|
int a, b = 0;
|
||||||
|
|
||||||
|
// function call by reference:
|
||||||
|
func1(&a, &b);
|
||||||
|
|
||||||
|
printf("Result %d, %d\n", a, b);
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
-> Referenzen auf Variablen werden übergeben.
|
||||||
|
Variablen sind im Hauptprogramm deklariert und definiert.
|
||||||
|
|
||||||
|
|
||||||
|
Es ist möglich für sehr schnelle Operation Register für Übergabe von Parametern benutzen.
|
||||||
|
Schlüsselwort Speicherklassenangabe /register/
|
||||||
|
|
||||||
|
Übergabe eines Arrays:
|
||||||
|
#+begin_src c
|
||||||
|
int func3(unsigned char * DataArray, unsigned short *DataLength){
|
||||||
|
int iRet = 0;
|
||||||
|
if (DataArray[0] == 0x55 && DataArray[1] == 0x33){
|
||||||
|
/* Do someting*/
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
iRet = -1; /* Wrong Header in array */
|
||||||
|
}
|
||||||
|
return(iRet);
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
Aufruf im Hauptprogramm (bitte die Dereferenzierung beachten)
|
||||||
|
#+begin_src c
|
||||||
|
//…
|
||||||
|
iRet = func3(&vbyData[0], &usDataLength);
|
||||||
|
//…
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Rückgabewerte
|
||||||
|
nur für Fehler
|
||||||
|
Erfolg ist 0
|
||||||
|
#+begin_src c
|
||||||
|
int iRet = 0;
|
||||||
|
iRet = func1(&DataArray[0], &DataLength);
|
||||||
|
if(iRet <0){
|
||||||
|
/* … Fehlerbehandlung … */
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Pointer
|
||||||
|
#+begin_src c
|
||||||
|
return_type function (xx_type const * pParam)
|
||||||
|
#+end_src
|
||||||
|
Beispiel:
|
||||||
|
(1) pParam ist ein
|
||||||
|
(2) Zeiger auf eine
|
||||||
|
(3) Konstante vom Typ
|
||||||
|
(4) xx_type
|
||||||
|
|
||||||
|
Zeiger auf Konstante: Eine Wertzuweisung ist nicht erlaubt/möglich (z.B.
|
||||||
|
~*pParam = 1.1f;~).
|
||||||
|
|
||||||
|
#+begin_src c
|
||||||
|
t_BYTE Data[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
||||||
|
t_BYTE *pData = &Data[0]; /* Data anstelle von &Data[0] moeglich */
|
||||||
|
/* pData = (t_BYTE *) &Data[0]; */
|
||||||
|
/* Adresszuweisung, der cast ist nicht zwingend notwendig */
|
||||||
|
printf("Der Pointer zeigt auf 0x%X mit dem Inhalt %d\n", pData, *pData);
|
||||||
|
pData++;
|
||||||
|
printf("Der Pointer zeigt auf 0x%X mit dem Inhalt %d\n", pData, *pData);
|
||||||
|
printf("Array Adresse: 0x%X 0x%x\n", &pData[0], &pData[1]);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Pointer Arithmetic
|
||||||
|
#+begin_src c
|
||||||
|
t_BYTE vbyData[20] = { 0x00 };
|
||||||
|
t_BYTE *pvbyData=NULL;
|
||||||
|
for (int i = 0; i < sizeof(vbyData); i++){ /* Init Array */
|
||||||
|
vbyData[i] = i+1;
|
||||||
|
}
|
||||||
|
pvbyData = (t_BYTE *) &vbyData[0];
|
||||||
|
/* Adresszuweisung, der cast ist nicht notwendig */
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++){
|
||||||
|
printf("0x%X ", *pvbyData);
|
||||||
|
pvbyData++;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
for (int i = 10; i > 5; i--){
|
||||||
|
printf("0x%X ", *pvbyData);
|
||||||
|
pvbyData--;
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** Pointer to struct
|
||||||
|
#+begin_src c
|
||||||
|
typedef struct strData{
|
||||||
|
t_WORD w1;
|
||||||
|
t_WORD w2;
|
||||||
|
};
|
||||||
|
|
||||||
|
strData strDataValue;
|
||||||
|
strData * pstrDataValue = NULL;
|
||||||
|
|
||||||
|
pstrDataValue = &strDataValue;
|
||||||
|
|
||||||
|
strDataValue.w1 = 0xAAEE;
|
||||||
|
strDataValue.w2 = 0xDDFF;
|
||||||
|
|
||||||
|
printf("Struct Adresse: 0x%X\n", &strDataValue);
|
||||||
|
printf("Struct Adresse Pointer 0x%X\n", pstrDataValue);
|
||||||
|
printf("Struct Inhalt, via Pointer 0x%X 0x%X\n", pstrDataValue->w1,pstrDataValue->w2);
|
||||||
|
printf("Wertausgabe ueber Pointer 0x%X\n", (*pstrDataValue).w1);
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
für verschachtelten struct siehe 06 P9
|
||||||
|
|
||||||
|
Zeiger auf Array, Interpretation als struct siehe 06 P10
|
||||||
|
|
||||||
|
*** function pointer
|
||||||
|
|
||||||
|
brauche ich für callback funktion
|
||||||
|
|
||||||
|
#+begin_src c
|
||||||
|
typedef void(*func)(int *par1, int *par2);
|
||||||
|
|
||||||
|
void func1(int *par1, int *par2){
|
||||||
|
*par1 = 5;
|
||||||
|
*par2 = 3;
|
||||||
|
}
|
||||||
|
void main(void){
|
||||||
|
func pFunc = NULL;
|
||||||
|
pFunc = func1;
|
||||||
|
pFunc(&a, &b);
|
||||||
|
printf("Werte %d, %d\n", a, b);
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Funktionszeiger werden eingesetzt bei der Registrierung von Callback Funktion einer übergeordneten Softwareschicht als Meldemedium für die unterlagerte Softwareschicht.
|
||||||
|
|
||||||
|
Funktionszeiger werden eingesetzt bei der Realisierung generischer Interfaces.
|
||||||
|
|
||||||
|
#+begin_src c
|
||||||
|
typedef int (*operation_ptr)(int,int);
|
||||||
|
int add(int a, int b) {return a + b;}
|
||||||
|
int mult(int a, int b) {return a * b;}
|
||||||
|
|
||||||
|
// or
|
||||||
|
//int do_operation(operation_ptr op, int x, int x){
|
||||||
|
int do_operation(int (*op)(int,int),int x, int y){
|
||||||
|
return op(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
int results = do_operation(add, 5, 34);
|
||||||
|
int results2 = do_operation(mult, 2,3);
|
||||||
|
}
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
*** UML
|
||||||
|
Mindestens jede Komponente, die aus mehreren Modulen bestehen kann, bekommt ein
|
||||||
|
Design, z.B. in UML (Enterprise Architekt).
|
||||||
|
*** Design for Testability:
|
||||||
|
Software soll bereits im Design die Testbarkeit berücksichtigen (STUB-
|
||||||
|
Barkeit, Datenaustausch per definiertem Interface, einfache Instrumentalisierung ohne die
|
||||||
|
Laufzeit zu beeinflussen, …)
|
||||||
|
*** Strukturierung eines Moduls
|
||||||
|
**** Sourcefile
|
||||||
|
- Headerkommentar:
|
||||||
|
Was für ein Modul, Copyright Notice, Versionierung des Moduls, …)
|
||||||
|
- Includes:
|
||||||
|
Es werden nur unterlagerte includes eingebunden mit Ausnahme weniger globaler Header
|
||||||
|
- Macros:
|
||||||
|
modullokal
|
||||||
|
- Typedefs:
|
||||||
|
modullokal
|
||||||
|
- Constants:
|
||||||
|
modullokal
|
||||||
|
- Global variables:
|
||||||
|
modullokal
|
||||||
|
- Prototypes:
|
||||||
|
modullokal
|
||||||
|
- Functions:
|
||||||
|
Der Kommentarblock enthält:
|
||||||
|
- Funktionsname,
|
||||||
|
- Beschreibung inkl. Bereichsgrenzen der Eingangs und Ausgangsvariablen,
|
||||||
|
- Beschreibung des Rückgabewertes,
|
||||||
|
- Beschreibung ggf. globaler verwendeter Variablen,
|
||||||
|
- Angabe des Erstellers, der Funktion und Datum der Erstellung.
|
||||||
|
- Jede Änderung der Funktion wird mit Datum und Name kommentiert
|
||||||
|
- EOF:
|
||||||
|
Modulfooter
|
||||||
|
- Jede Sektion wird durch einen Kommentar eingeleitet
|
||||||
|
- Eine Funktion GetVersion() zur Rückgabe der Modulversion ist verpflichtend.
|
||||||
|
~#define MAJOR_VERSION 01~
|
||||||
|
~#define MINOR_VERSION 00~
|
||||||
|
~#define PATCH_VERSION 00~
|
||||||
|
- Es ist wichtig ein eindeutiges Versionierungsschema möglichst früh zu vereinbaren.
|
||||||
|
- Die Anzahl der Codezeilen pro C-Datei soll 1000 NCLOC (Non Comment Lines Of Code) nicht überschreiten.
|
||||||
|
- Die Anzahl der NCLOC (Non Comment Lines Of Code) pro Funktion soll 100 nicht überschreiten.
|
||||||
|
- Globale Variablen sind grundsätzlich zu vermeiden, so wenig wie möglich.
|
||||||
|
- Globale oder modulglobale Variablen und Strukturen sollten grundsätzlich in einer MSN_Init() Funktion zur Laufzeit initialisiert werden. Dies ermöglicht es die Komponente mehrmals im Programmablauf wieder auf den Ausgangszustand zurückzusetzen, was v.a. bei Modultests sehr hilfreich ist.
|
||||||
|
**** Gruppierung modulglobaler Statusvariablen mittels struct
|
||||||
|
Guter Designstil ist es den internen Status eines Moduls in einer Struktur zu kapseln.
|
||||||
|
#+begin_src c
|
||||||
|
unsigned char ucStateCounter1;
|
||||||
|
unsigned long ulWorkingClock;
|
||||||
|
unsigned long ulMsSinceStartup;
|
||||||
|
unsigned char ucStage;
|
||||||
|
int iGlobalError;
|
||||||
|
unsigned char ucStatus;
|
||||||
|
#+end_src
|
||||||
|
->
|
||||||
|
#+begin_src c
|
||||||
|
typedef struct {
|
||||||
|
unsigned char ucStateCounter1;
|
||||||
|
unsigned long ulWorkingClock;
|
||||||
|
unsigned long ulMsSinceStartup;
|
||||||
|
unsigned char ucStage;
|
||||||
|
int iGlobalError;
|
||||||
|
unsigned char ucStatus;
|
||||||
|
}t_GlobalState;
|
||||||
|
|
||||||
|
t_GlobalState GlbState;
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
- Lesbarkeit:
|
||||||
|
Ein gut dokumentierter struct erleichtert an zentraler Stelle den Einstieg in die internen Abläufe des Moduls
|
||||||
|
Die relevanten modulglobalen Variablen sind an zentraler Stelle zusammengefasst.
|
||||||
|
- Debugability:
|
||||||
|
Das Debuggen wird erleichtert, es muss nur eine Struktur in das WatchWindow gezogen werden.
|
||||||
|
- Testability:
|
||||||
|
Der interne Status des Moduls lässt sich einfach serialisieren und über eine Kommunikationsschnittstelle übertragen für zum Beispiel eine messtechnische Verwendung.
|
||||||
|
**** Headerfiles
|
||||||
|
- Das zu einem Modul gehörende Headerfile bildet das Interface nach außen. Hier wird nur das abgebildet, was zur Verwendung des Moduls von außen benötigt wird.
|
||||||
|
- Das Headerfile beginnt mit einem Include Guard, um Mehrfachinkludierung zu vermeiden.
|
||||||
|
~#ifndef GRANDFATHER_H~
|
||||||
|
~#define GRANDFATHER_H~
|
||||||
|
- Globale Variablen dürfen im Headerfile nur deklariert werden aber nicht definiert werden.
|
||||||
|
Beispiel: ~extern int iTest;~
|
||||||
|
- Externe Funktionen dürfen in einem Headerfile nur deklariert aber nicht definiert werden
|
||||||
|
Beispiel: ~extern void func (void);~
|
||||||
|
Anmerkung:
|
||||||
|
Eine Ausnahme gilt für inline Funktionen.
|
||||||
|
- Ein Modul bekommt zwei Headerfiles:
|
||||||
|
➔ Modulename.h
|
||||||
|
Interface (Deklaration) für das überlagerte Modul
|
||||||
|
➔ Modulename_cfg.h
|
||||||
|
Konfigurationsinterface für das Modul (#define)
|
||||||
|
- Ein Modul wird so aufgebaut, dass ein Dritter der das Modul verwendet, nur die Headerfiles als Interface benötigt, um mit dem Modul arbeiten zu können.
|
||||||
|
- Im Headerfile deklarierte globale Variablen und Funktionen wird eine Modulkurzkennung bestehend aus drei Buchstaben gefolgt von „_“ vorangestellt.
|
||||||
|
Beispiel:
|
||||||
|
~MSN_TestFunc(…)~
|
||||||
|
MSN steht für „Module Short Name“
|
||||||
|
− Tailoring:
|
||||||
|
Im Konfigurationsheader ist ein Tailoring (Anpassung) einer SW-Komponenten auf den aktuellen Verwendungskontext vorzunehmen.
|
||||||
|
− Tailoring optional:
|
||||||
|
Ausprogrammierung plattform-spezifischer Funktionsinhalte mittels gesondertem _cfg.c file, das über den cfg.h eingebunden wird.
|
||||||
|
|
||||||
|
*** Kommentare
|
||||||
|
- Es gibt zwei Arten um einen Kommentar zu markieren:
|
||||||
|
den mit ~// eingeleiteten C++ Kommentar~
|
||||||
|
den in ~/* geklammerten C Kommentar */~
|
||||||
|
- Für automotive embedded Templates wird nur der C Kommentarstil vereinbart.
|
||||||
|
|
||||||
|
** Rectangle Method
|
||||||
|
$$I_2=\int_b^af(x)fx$$
|
||||||
|
|
||||||
|
$$\approx h \sum_{i=1}^n f({x_{i-1}+x_i}/2)$$
|
||||||
|
|
||||||
|
** Trapezoid Method
|
||||||
|
$$I_T = \int_a^b f(x)dx$$
|
||||||
|
|
||||||
|
$$ \approx h/2 \sum_{i=1}^{n}f(x_{i-1})+f(x_i))$$
|
||||||
|
|
||||||
|
$$ = h/2 (f(x_0)+2f(x_1)+\dots+2f(x_{n-1})+f(x_n))$$
|
||||||
|
|
||||||
|
** Simpson Method
|
||||||
|
|
||||||
|
$$I = \int_a^bf(x)dx$$
|
||||||
|
$$ \approx (h/3) [f(x_0)+4f(x_1)+2f(x_2)+ \dots 2f(x_{n-2})+4f(x_{n-1})+f(x_n)]$$
|
||||||
|
|
||||||
4
test.drawio.svg
Normal file
4
test.drawio.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 59 KiB |
Reference in New Issue
Block a user