改为matlab语言#pragma region TanVecB_basis double RoutePlan::TanVecB_basis(double u, double *U, int i) { double N_, deta1, deta2, A, B1; struct _Matrix N; Matrix_set_m(&N, 3); Matrix_set_n(&N, 3); Matrix_init_matrix(&N); //printf("i = %d\n", i); (u >= U[i] && u <= U[i + 1]) ? Matrix_write(&N, 0, 0, 1) : Matrix_write(&N, 0, 0, 0); (u >= U[i + 1] && u <= U[i + 2]) ? Matrix_write(&N, 1, 0, 1) : Matrix_write(&N, 1, 0, 0); (u >= U[i + 2] && u <= U[i + 3]) ? Matrix_write(&N, 2, 0, 1) : Matrix_write(&N, 2, 0, 0); //printf("u= %f \n", u); for (int j = 1; j < 3; j++) { for (int k = 0; k < 3 - j; k++) { deta1 = U[i + j + k] - U[i + k]; deta2 = U[i + j + k + 1] - U[i + k + 1]; (deta1 == 0) ? (A = 0) : (A = (u - U[i + k]) / deta1); (deta2 == 0) ? (B1 = 0) : (B1 = (U[i + j + k + 1] - u) / deta2); Matrix_write(&N, k, j, A*Matrix_read(&N, k, j - 1) + B1*Matrix_read(&N, k + 1, j - 1)); //printf("deta1= %f \n", deta1); printf("deta2= %f \n", deta2); } } Matrix_write(&N, 2, 1, 0); Matrix_write(&N, 2, 2, 0); Matrix_write(&N, 1, 2, 0); //printff_matrix(&N); N_ = Matrix_read(&N, 0, 2); //printf(" N_ =%f \n", N_); return N_; } #pragma endregion
时间: 2024-04-19 16:28:23 浏览: 72
function N_ = TanVecB_basis(u, U, i)
N = zeros(3, 3);
N(1, 1) = (u >= U(i) && u <= U(i + 1));
N(2, 1) = (u >= U(i + 1) && u <= U(i + 2));
N(3, 1) = (u >= U(i + 2) && u <= U(i + 3));
for j = 2 : 3
for k = 1 : 3 - j + 1
deta1 = U(i + k + j - 1) - U(i + k - 1);
deta2 = U(i + k + j) - U(i + k);
A = (deta1 == 0) * 0 + (deta1 ~= 0) * (u - U(i + k - 1)) / deta1;
B1 = (deta2 == 0) * 0 + (deta2 ~= 0) * (U(i + k + j) - u) / deta2;
N(k, j) = A * N(k, j - 1) + B1 * N(k + 1, j - 1);
end
end
N(3, 2) = 0;
N(3, 3) = 0;
N(2, 3) = 0;
N_ = N(1, 3);
end
相关问题
转为matlab语言#pragma region TanVecB_basis double RoutePlan::TanVecB_basis(double u, double *U, int i) { double N_, deta1, deta2, A, B1; struct _Matrix N; Matrix_set_m(&N, 3); Matrix_set_n(&N, 3); Matrix_init_matrix(&N); //printf("i = %d\n", i); (u >= U[i] && u <= U[i + 1]) ? Matrix_write(&N, 0, 0, 1) : Matrix_write(&N, 0, 0, 0); (u >= U[i + 1] && u <= U[i + 2]) ? Matrix_write(&N, 1, 0, 1) : Matrix_write(&N, 1, 0, 0); (u >= U[i + 2] && u <= U[i + 3]) ? Matrix_write(&N, 2, 0, 1) : Matrix_write(&N, 2, 0, 0); //printf("u= %f \n", u); for (int j = 1; j < 3; j++) { for (int k = 0; k < 3 - j; k++) { deta1 = U[i + j + k] - U[i + k]; deta2 = U[i + j + k + 1] - U[i + k + 1]; (deta1 == 0) ? (A = 0) : (A = (u - U[i + k]) / deta1); (deta2 == 0) ? (B1 = 0) : (B1 = (U[i + j + k + 1] - u) / deta2); Matrix_write(&N, k, j, A*Matrix_read(&N, k, j - 1) + B1*Matrix_read(&N, k + 1, j - 1)); //printf("deta1= %f \n", deta1); printf("deta2= %f \n", deta2); } } Matrix_write(&N, 2, 1, 0); Matrix_write(&N, 2, 2, 0); Matrix_write(&N, 1, 2, 0); //printff_matrix(&N); N_ = Matrix_read(&N, 0, 2); //printf(" N_ =%f \n", N_); return N_; } #pragma endregion
请注意,我不支持编译和运行代码。我只能帮助你理解和转换代码。下面是将该代码转换为MATLAB语言的结果:
```matlab
function N_ = TanVecB_basis(u, U, i)
N = zeros(3, 3);
if (u >= U(i) && u <= U(i + 1))
N(1, 1) = 1;
else
N(1, 1) = 0;
end
if (u >= U(i + 1) && u <= U(i + 2))
N(2, 1) = 1;
else
N(2, 1) = 0;
end
if (u >= U(i + 2) && u <= U(i + 3))
N(3, 1) = 1;
else
N(3, 1) = 0;
end
for j = 2:3
for k = 1:(3 - j)
deta1 = U(i + j + k) - U(i + k);
deta2 = U(i + j + k + 1) - U(i + k + 1);
if (deta1 == 0)
A = 0;
else
A = (u - U(i + k)) / deta1;
end
if (deta2 == 0)
B1 = 0;
else
B1 = (U(i + j + k + 1) - u) / deta2;
end
N(k, j) = A * N(k, j - 1) + B1 * N(k + 1, j - 1);
end
end
N(3, 2) = 0;
N(3, 3) = 0;
N(2, 3) = 0;
N_ = N(1, 3);
end
```
请注意,此转换是基于代码的结构和逻辑进行的。可能会有一些细微的差异,具体取决于MATLAB的实现方式和其他上下文。确保在使用转换后的代码时进行测试和验证。
阅读全文