My first programming language is python and now im trying to convert the python code to C++ code. C++ code will be used later in QT Creator.
My python code is :
import numpy as np
P0 = 10
P1 = 20
P2 = 30
P3 = 40
Koef = [[-1,3,-3,1],[2,-5,4,-1],[-1,0,1,0],[0,2,0,0]]
mKoef = np.matrix(Koef)
Px = [[P0],[P1],[P2],[P3]]
mPx = np.matrix(Px)
t = 0.01
sr = [t**3,t**2,t,1]
msr = np.matrix(sr)
C = 0.5 * msr * mKoef * mPx
print(C)
And the result which i get is 20.1. But if I try to do same operation in C++ i get '0x75cc60' with no errors. I don't even know what it means.
My C++ code (UPDATED!) : Now i get correct result 20.1. But for some reason if i comment out MatrixP2 the code doesn't work. And there seems to be a problem with reading values from MatrixProduct for some reason.
float t = 0.01;
int P0 = 10;
int P1 = 20;
int P2 = 30;
int P3 = 40;
float t3 = pow(t,3);
float t2 = pow(t,2);
int MatrixKoef[4][4] = {{-1, 3, -3, 1}, {2, -5, 4, -1}, {-1, 0, 1, 0}, {0, 2, 0, 0}};
float MatrixSR[1][4] = {t3,t2,t,1};
int MatrixP[4][1] = {{P0},{P1},{P2},{P3}};
int MatrixP2[1][4] = {5,4,3,2};
float MatrixProduct[1][1] = {0};
float MatrixFinale[1] = {0};
for (int row = 0; row < 1; row++) {
for (int col = 0; col < 4; col++) {
for (int inner = 0; inner < 4; inner++) {
MatrixProduct[row][col] += 0.5 * MatrixSR[row][inner] * MatrixKoef[inner][col];
}
std::cout << MatrixProduct[row][col] << " ";
}
std::cout << "\n";
}
for (int row = 0; row<1;row++){
for (int col = 0; col<4; col++){
MatrixFinale[0] += MatrixProduct[1][-1+col] * MatrixP[0][col];
std::cout << MatrixProduct[1][-1+col] << " ";
std::cout << MatrixP[0][col] << " ";
std::cout << col;
std::cout << "\n";
}
std::cout << MatrixFinale[0] << " ";
}
All help will be appreciated! Thank you.