How can I pass in variables into fsolve()?
이전 댓글 표시
Say I have some matrix 3x3 matrix, A, that is defined as:
for ii = 1:length(layers+1)
A(ii) = [k0^2*eO(ii)-ky^2-kz^2,k0^2*eH(ii)+kx*ky,kx*kz;
kx*ky-k0^2*eH(ii),k0^2*eO(ii)-kx^2-kz^2,ky*kz;
kx*kz,ky*kz,k0^2*eE(ii)-kx^2-ky^2];
end
I am defining every variable in this matrix except for "kz". I'm trying to solve where the determinant of A is equal to zero. The catch is i don't want to use some variation of:
syms kz
kz = solve(det(A) == 0,kz);
because this is a function that is called several hundred thousand times through my main code and I would like to avoid using syms as it is slow.
Now, I've read up on a function called fsolve() and can't seem to figure out how to pass in the known variables of A to this section of code:
fun = @det0
x0 = zeros(4,1);
kz = fsolve(fun,x0);
function F = det0(kz)
F = det([k0^2*eO-ky^2-kz^2,k0^2*eH+kx*ky,kx*kz;
kx*ky-k0^2*eH,k0^2*eO-kx^2-kz^2,ky*kz;
kx*kz,ky*kz,k0^2*eE-kx^2-ky^2]);
Let me know if you need more information to help solve this problem. Thanks!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!