# EmbeddedLapack
![](https://raw.githubusercontent.com/DanielMartensson/EmbeddedAlgebra/master/C-symbol.png) ![](https://raw.githubusercontent.com/DanielMartensson/EmbeddedAlgebra/master/CPU-symbol.png)
![](https://raw.githubusercontent.com/DanielMartensson/EmbeddedAlgebra/master/Matrix-symbol.png)
## Introduction
This is a C-library for linear algebra which is meant to be used for embedded systems such as AVR, PIC, ARM etc. The library is
built easily and follows the MATLAB/Octave "standard" as much as it can when computing and solving matrices.
This C-library uses Lapack subroutines from Lapack version 3.2.1 and I have changed this Lapack library so it does not require a specific CPU/computer or asking for an operating system. I want this library to have 100% portability.
* Easy to use in the editor
* Basic easy code to read if needed
* Follows MATLAB commands as much as it can
* Can be used with a compiler as low as C99 standard, default is C11
* Simple use for most common matrix algebra
* Using minimal but necessary Lapack subroutines as possible due to the small amout of flash memory it will be loaded into.
If you are looking for an even smaller library that performs the same job (except for imaginary eigenvectors), then CControl will be a good alternative. CControl is more applied and contains lots of examples such as system identification, path finding, linear algebra, filtering, control engineering, optimization etc. CControl does not use LAPACK therefore it fits even on smaller microcontrollers. Please fork and star so more people can see CControl.
2023-07-31: This library is now supporting LAPACK for embedded systems.
https://github.com/DanielMartensson/CControl
## Status of the project
Support for this project is ongoing and is subject to found bugs or when new features are added otherwise everything on the main branch is currently functional.
## Tested on the following without any compile errors
* Windows 7 MinGW 64 bit
* Ubuntu Linux GCC 64 bit
* Raspberry Pi B+/Zero W GCC-ARM 32 bit
* STM32 GCC-ARM-Atollic 32 bit
## Installation for testing and buildning your matrix algebra
Step 1: Download EmbeddedLapack folder
Step 2: Open EmbeddedLapack and go to Debug folder
Step 3:
Execute this to compile
```
make clean
make
```
## Installation to an embedded target
Step 1: Download EmbeddedLapack folder
Step 2: Move the folders "Lapack" and "LinearAlgebra" from the folder EmbeddedLapack -> src, to the same folder as your main.c file is located.
Step 3: Link "-lm" like this.
![](https://raw.githubusercontent.com/DanielMartensson/EmbeddedLapack/master/Markering_006.png)
Step 4: Paste in "#include "LinearAlgebra/declareFunctions.h"" in top of your main.c file
![](https://raw.githubusercontent.com/DanielMartensson/EmbeddedLapack/master/Markering_008.png)
Done! Now you can compile.
## Functions
```
void tran(double* A, int row, int column);
void print(double* A, int row, int column);
void linsolve(double* A, double* X, double* B, int row, int column_b);
void svd(double* A, double* U, double* S, double* V, int row, int column);
void diag(double* A, double* B, int row_b, int column_b);
void qr(double* A, double* Q, double* R, int row, int column);
void triu(double* A, double* B, int shift, int row, int column);
void eye(double* A, int row, int column);
void mul(double* A, double* B, bool elementWise, double* C, int row_a, int column_a, int column_b);
void scale(double* A, double scalar, int row, int column);
void sub(double* A, double* B, double* C, int row_a, int column_a, int column_b);
void lu(double* A, double* L, double* U, double* P, int row, int column);
void tril(double* A, double* B, int shift, int row, int column);
void inv(double* A, int row);
void chol(double* A, double* L, int row);
double det(double *A, int row);
void toeplitz(double* A, double* B, int length);
void hankel(double* A, double* H, int length, int step);
void cut(double* A, int row, int column, double* B, int start_row, int stop_row, int start_column, int stop_column);
void diagpower(double* A, double p, int row, int column);
void eabs(double* A, int row, int column);
void add(double* A, double* B, double* C, int row_a, int column_a, int column_b);
void copy(double* A, double* B, int row, int column);
void cofact(double* A, double* CO, int row, int column);
void mdiag(double* A, double* B, int row, int column);
double dot(double* A, double* B, int row);
void horzcat(double* A, double* B, double* C, int row_a, int column_a, int column_b);
void maxvector(double* A, int row, double* val, int* index);
void minvector(double* A, int row, double* val, int* index);
double norm(double* A, int row, char* P);
void ones(double* A, int row, int column);
void pinv(double* A, int row, int column);
void power(double* A, int row, int column, double value);
void repmat(double* A, int row, int column, int horz, int vert, double* B);
void sqrte(double* A, int row, int column);
void sumrows(double* A, double* B, int row, int column);
void vec(double* A, double* B, int row, int column);
void vertcat(double* A, double* B, double* C, int row_a, int column_a, int row_b);
void zeros(double* A, int row, int column);
int rank(double* A, int row);
void eig(double* A, double* Ereal, double* Eimag, double* Vreal_left, double* Vimag_left, double* Vreal_right, double* Vimag_right, int row);
void mpower(double* A, int row, int n);
void insert(double* A, double* B, int row_a, int column_a, int column_b, int startRow_b, int startColumn_b);
void move(double* A, int row, int column, int down, int right);
void quadprog(double* H, double* g, double* A, double* ulb_vec, double* uub_vec, double* ylb_vec, double* yub_vec, int* nWSR, double* u, int columnH, int rowA);
void linprog(double* c, double* A, double* b, double* x, int row_a, int column_a, uint8_t max_or_min, int iteration_limit);
```
## Compiler and microprocessor
When you compile this, you need to take respect on this.
```
#include <math.h> // Need be linked with "-lm" when compiling this code
```
Also you need to link the folder "Include" located inside EmbeddedLapack -> src -> Lapack.
## Troubleshooting
If you declare a matrix or a vector and you use that with this library, but you getting garbage values back. Try to sett all values of the matrix or vector to zeros by using:
```
zeros(A, row, column);
```
Most of my functions have this algorithm included in the beginning of the functions.
## Examples and how to use
Here is some examples how to use
## QR-factorization
```
#include <time.h>
#include "LinearAlgebra/declareFunctions.h"
int main() {
clock_t start, end;
float cpu_time_used;
start = clock();
// A matrix with size 6 x 4
double A[6*4] = {0.674878, 0.151285, 0.875139, 0.150518,
0.828102, 0.150747, 0.934674, 0.474325,
0.476510, 0.914686, 0.740681, 0.060455,
0.792594, 0.471488, 0.529343, 0.743405,
0.084739, 0.475160, 0.419307, 0.628999,
0.674878, 0.151285, 0.875139, 0.150518};
double Q[6*6];
double R[6*4];
// Solve
qr(A, Q, R, 6, 4);
// Print
print(A, 6,4);
print(Q, 6,6);
print(R, 6,4);
end = clock();
cpu_time_used = ((float) (end - start)) / CLOCKS_PER_SEC;
printf("\nTotal speed was %f,", cpu_time_used);
return 0;
}
```
## Singular Value Decomposition
```
#include <time.h>
#include "LinearAlgebra/declareFunctions.h"
#define row 17
#define column 15
int main( )
{
clock_t start, end;
float cpu_time_used;
start = clock();
double A[row*column] = {
0.84245, 0.23405 , 0.69751 , 0.27905 , 0.18851 , 0.61018 , 0.62182 , 0.71839 , 0.79161 ,0.56156 , 0.83395 , 0.092388 , 0.8511 , 0.44826 , 0.82158,
0.84614 , 0.15947 , 0.096336 , 0.80793 , 0.35114 , 0.42583 , 0.2134 , 0.75324 , 0.31391 , 0.22892 , 0.94773 , 0.81204 , 0.62554 , 0.28367 , 0.26637,
0.26509 , 0.91429 , 0.14222 , 0.28321 , 0.11607 , 0.41188 , 0.10071 , 0.18224 , 0.757
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计&课设-MATLAB风格的嵌入式系统线性代数.zip
共741个文件
d:230个
o:230个
c:230个
需积分: 1 0 下载量 101 浏览量
2024-01-08
22:32:54
上传
评论
收藏 13.12MB ZIP 举报
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计&课设-MATLAB风格的嵌入式系统线性代数.zip (741个子文件)
QProblem.c 202KB
dgesvd.c 125KB
QProblemB.c 94KB
dlaqr5.c 33KB
slaqr5.c 33KB
dtrevc.c 32KB
strevc.c 32KB
dlamch.c 26KB
dlaqr0.c 26KB
dlaqr4.c 26KB
slamch.c 26KB
slaqr0.c 25KB
slaqr4.c 25KB
dbdsqr.c 25KB
MessageHandling.c 24KB
Utils.c 23KB
Matrices.c 23KB
dlaqr3.c 22KB
slaqr3.c 21KB
dlaqr2.c 21KB
slaqr2.c 21KB
dlarfb.c 20KB
slarfb.c 20KB
ilaenv.c 19KB
dlahqr.c 19KB
slahqr.c 19KB
dhseqr.c 18KB
shseqr.c 18KB
dgeev.c 18KB
sgeev.c 17KB
dlarfx.c 17KB
slarfx.c 17KB
Options.c 17KB
dlaln2.c 16KB
slaln2.c 16KB
dlasq2.c 15KB
dlabrd.c 15KB
dlasy2.c 14KB
slasy2.c 14KB
Constraints.c 14KB
OQPinterface.c 14KB
Bounds.c 13KB
dlasr.c 13KB
dlaexc.c 13KB
slaexc.c 12KB
dtrsm.c 12KB
strsm.c 12KB
dtrmm.c 11KB
strmm.c 11KB
dgebrd.c 11KB
dgehrd.c 11KB
linprog.c 11KB
sgehrd.c 10KB
dormbr.c 10KB
dgemm.c 10KB
sgemm.c 10KB
dtrexc.c 10KB
dlahr2.c 10KB
strexc.c 10KB
iparmq.c 10KB
slahr2.c 10KB
dlarft.c 9KB
dgebd2.c 9KB
slarft.c 9KB
dgebal.c 9KB
dormlq.c 9KB
sgebal.c 9KB
dlasq4.c 9KB
dormqr.c 9KB
sormqr.c 9KB
dlasq3.c 9KB
dorgbr.c 9KB
dlascl.c 9KB
slascl.c 8KB
dtrmv.c 8KB
strmv.c 8KB
dorgqr.c 8KB
dorglq.c 8KB
dormhr.c 8KB
sorgqr.c 8KB
sormhr.c 7KB
dgemv.c 7KB
sgemv.c 7KB
dgeqrf.c 7KB
dgelqf.c 7KB
dlasv2.c 7KB
dlasq1.c 6KB
dgetrf.c 6KB
sgetrf.c 6KB
dlanv2.c 6KB
dorm2r.c 6KB
dorml2.c 6KB
dlasq5.c 6KB
sorm2r.c 6KB
slanv2.c 6KB
Indexlist.c 6KB
dgehd2.c 6KB
dorghr.c 6KB
dgebak.c 6KB
dlasrt.c 6KB
共 741 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
白话机器学习
- 粉丝: 9917
- 资源: 7681
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功