我是机械工程师,非常擅长C语言
想要使用函数Summation求和1x14矩阵Cx1 Cy1 Cz1中所有组件的总和
我也想做(Cx1 *转置(Ma))/ sum(Ma)(得到质心)的计算
谁能帮帮我?我只习惯使用matlab,所以我很难使用函数或指针 (我使用wiringPi,因为我必须使用Raspberry pi运行它...)#include <stdio.h>
#include <wiringPi.h>
#include <stdlib.h>
#include <errno.h>
#include <wiringSerial.h>
#include <math.h>
void MatrixMultiply(int m, int p, int n, float A[m][p], float B[p][n], float C[p][n])
{
int i, j, k;
for (i=0;i<m;i++)
for(j=0;j<n;j++)
{
C[i][j]=0;
for (k=0;k<p;k++)
C[i][j]= C[i][j]+A[i][k]*B[k][j];
}
}
void Summation(int m,int n, double Cx[n], double Cy[n], double Cz[n], double M[n])
{
int i;
double sum_x =0;
double sum_y =0;
double sum_z =0;
double CG_x1 = 0;
double CG_y1 = 0;
double CG_z1 = 0;
double Mass = 0;
double Cx1[14] = {-0.00037435797,0,0,0.00118574942,3.07214914879,0,-3.53615559888,3.53615559888,-3.49598511933,-0.58036525258,-2.58027392955,0,3.53315689833,-0.00339553944};
double Cy1[14] = {-0.00091507094,0,0,0.00067588546,1.79688158586,0.37033689898,4.68812966408,-4.68812966408,1.38566975835,-3.72451299038,-1.48972184781,0,1.67480858582,-0.00196041565};
double Cz1[14] = {0.39494859708,-0.1525,5.91074892102,2.82120389989,4.13903790555 ,2.00112984375,4.79000000005 ,4.79000000005,3.20714937209,3.22445881918 ,1.38480905325,0.85250000000,11.28209081559,9.29000000000};
double Ma[14] = {0.55884245503, 0.60366974489, 3.95197090345, 20.82750506085, 2.46150714667, 0.31070393824, 0.64982394170, 0.64982394170, 2.53800582113,2.53800582113, 2.50769704699, 0.86840073405, 0.17496883559, 0.56740282314, 0.6989733086 };
for(i = 0;i<m;i++)
{
sum_x += Cx1[i];
sum_y += Cy1[i];
sum_z += Cz1[i];
Mass += M[i];
}
}
double main(void)
{
double sum_x =0;
double sum_y =0;
double sum_z =0;
double CG_x1 = 0;
double CG_y1 = 0;
double CG_z1 = 0;
double Mass = 0;
Summation(15,14,double Cx1,double Cy1,double Cz1,double Ma);
MatrixMUltiply(?)
printf("x = %15.15f\n, y = %15.15f\n, z = %15.15f\n Mass = %15.15f\n",sum_x,sum_y,sum_z};
}
答案 0 :(得分:0)
以下是在C中进行矩阵乘法的示例程序: http://www.programiz.com/c-programming/examples/matrix-multiplication-function
您还可以在此处阅读C教程: http://www.w3schools.in/c-tutorial/