Solving for all missing terms at once with "solve" doesn't work
显示 更早的评论
Hello,
I am trying to write a function to automate solving the following problem:
- Given 3D unit vectors N, O, and A with at least 3 knowns (the rest could be symbols)
- Given N is orthogonal to both O and A
- Find the missing vector components
The equations that relate N, O, and A to each other are:
- cross(O, A) == N
- norm(N) == 1
- norm(O) == 1
- norm(A) == 1
Simple example done manually:
syms nx ny nz oz
A = [-0.9100; -0.4146; 0];
O = [0.3362; -0.7379; oz];
N = [nx; ny; nz]
% Solve for z component in the O vector
solve(norm(O) == 1, oz)
% oz: (5^(1/2)*6849463^(1/2))/10000
% Solve for all three components in N vector
solve(cross(O, A) == N, nx, ny, nz)
% nx: (2073*oz)/5000
% ny: -(91*oz)/100
% nz: -10135969/12500000
OK, so clearly that works. Next I would like to write a function to do this:
function S = noa(N, O, A)
S = solve([
cross(O, A) == N,
norm(N) == 1,
norm(O) == 1,
norm(A) == 1
]);
end
When I execute it using the values for N, O and I in example above, I get no solutions
noa(N, O, A)
% nx: [0x1 sym]
% ny: [0x1 sym]
% nz: [0x1 sym]
% oz: [0x1 sym]
I would also like to generate C code:
ccode(noa(N, O, A))
...but it's complaining about an incorrect number of inputs/outputs even though I provided the correct number
Incorrect number or types of inputs or outputs for function 'ccode'.
Does anyone know what might be wrong here?
Thank you!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!