为什么直接算不出来P,算出来都是0?
其实都是matlab
clc
clear
close all
% 一、构造校验矩阵 H 和生成矩阵 G
% 1. 构造校验矩阵 H
H = [0 0 0 1 1 1 1;
0 1 1 0 0 1 1;
1 0 1 0 1 0 1];
% 2. 构造生成矩阵 G
% 通过 H 和单位矩阵的关系求解 P
syms k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12
assume(k1 == 0 | k1 == 1);
assume(k2 == 0 | k2 == 1);
assume(k3 == 0 | k3 == 1);
assume(k4 == 0 | k4 == 1);
assume(k5 == 0 | k5 == 1);
assume(k6 == 0 | k6 == 1);
assume(k7 == 0 | k7 == 1);
assume(k8 == 0 | k8 == 1);
assume(k9 == 0 | k9 == 1);
assume(k10 == 0 | k10 == 1);
assume(k11 == 0 | k11 == 1);
assume(k12 == 0 | k12 == 1);
P=zeros(4,3);
P = [k1 k2 k3;
k4 k5 k6;
k7 k8 k9;
k10 k11 k12];
I = eye(4);
G = [I P]; % 使用 P 的转置与 I 拼接
Z=zeros(4,3);
eqns1 = [G*H'==Z];
S1 = solve(eqns1, [k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12]);
P=[S1.k1 S1.k2 S1.k3;
S1.k4 S1.k5 S1.k6;
S1.k7 S1.k8 S1.k9;
S1.k10 S1.k11 S1.k12];