Last active
June 27, 2024 16:43
-
-
Save adler3d/a664818673075b62a37ff803f2682e43 to your computer and use it in GitHub Desktop.
умножение матрицы на вектор в с++ используя std::array и шаблоны
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <array> | |
using namespace std; | |
template<class real,size_t h,size_t w> | |
void mul(const array<array<real,w>,h>&m,const array<real,w>&v,array<real,h>&out){ | |
for(size_t y=0;y<h;y++){ | |
auto&s=out[y];s={}; | |
for(size_t x=0;x<w;x++){ | |
s+=v[x]*m[y][x]; | |
} | |
} | |
} | |
int main(){ | |
typedef array<double,3> t_vec; | |
array<t_vec,2> m={ | |
t_vec{0,1,3}, | |
t_vec{4,5,6} | |
}; | |
array<double,3> v={10,11,12}; | |
array<double,2> result{}; | |
mul(m,v,result); | |
for(auto&x:result)cout<<" "<<x; | |
cout<<endl; // 47 167 | |
return 0; | |
} |
array<t_vec,3> m={
t_vec{+3,+2,-1},
t_vec{+2,-2,+4},
t_vec{-1,0.5,-1}
};
t_vec point={1,-2,0};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
сейчас попробую решить вот эту систему линейных уравнений из вики:
