How to split a function_handle into two separate functions (real part and imaginary part) to apply Newton Raphson

3 ビュー (過去 30 日間)
I am trying to solve an eigenvalue problem with the following general form:
syms k tau
...
B = @(k, tau) det((K_inv * A_k) - (tau*I));
Where K_inv and A_k are just matrices defined as a function of k and I is just the identity matrix (2x2 in this case). For example, the term (1,2) of the A_k matrix is equal to:
A_k(1,2)
ans =
-(k*(67/(200*(3i/(10*k) - 1)) + 33/(200*(91i/(2000*k) - 1)) + 2)*1i + 67/(100*(3i/(10*k) - 1)) + 33/(100*(91i/(2000*k) - 1)) + 2)/(22*k^2)
B is a function that is equal to the determinant of the expression that's inside. And I can either define it this way (output being a function_handle) or without the @(k, tau) at the beginning which would give me a very long expression like the one above but defined as a function of both k and tau.
My intention is to find the values of k and tau that are a solution to the system. In order to do that, I want to use the Newton Raphson method. If I'm not mistaken, I need to define my two equations in order to find the derivative and iterate. However, I can't find a way to make one of the N-R codes in Mathworks work. I would like to define my two functions:
  • one being the real part of B and
  • one being the imaginary part of B
That's to say, split the function in two to feed it as an input to any of the N-R codes that are published (or build my own one, if I need to).
I'm attaching the output of B as a function of k and tau (which could be used as a starting point for the problem) below, if that helps:
ans =
-(- 44937223426059303978838209331200000*k^4*tau^2 + 62291687957452331354586870500556800000*k^4*tau - 15958741989441089831892218426913000000*k^4 + k^3*tau^2*15525810693703489524688601323929600i - k^3*tau*26122737598459740879919621702313574400i + k^3*6742533603806311275007134855211441500i + 613393099765709499311141557370880*k^2*tau^2 - 3792357385283446219346006966896951296*k^2*tau - 300114415316023619206890688620559815*k^2 + k*tau*657203153098993879589333656921964544i + k*529561528682743172861584156368762120i + 27881476653304494049132515982049280*tau + 26667418360592402625087613769684400)/(2246861171302965198941910466560*k^2*(10*k - 3i)*(2000*k - 91i))
As you can see, it is ridiculously long. I've tried typing real(B) and imag(B) but that only seems to add the words real and imag in front of the expression above without reducing the number of terms that don't belong there.
Once these two equations are defined (if I somehow manage to achieve that), what would be the next step to find the solution of k and tau?
I found this simple code online:
format long g % show all digits
x = [0;0]; % initial guess
while 1
b = f(x); % evaluate f
A = fp(x); % evaluate Jacobian
d = -A\b; % solve A*d = -b
x = x + d
if norm(d)<=1e-13 % stop iteration if norm(d)<=StepTolerance
break
end
end
plot(x(1),x(2),'o'); hold off % mark solution point with 'o'
But I'd need to define f(x) - my function, and fp(x) - the jacobian, which I don't really know how to find in this specific problem.
Any ideas on how to proceed to solve my problem? Thanks in advance.

回答 (0 件)

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by