Help with finding zeros of a complex function

8 ビュー (過去 30 日間)
Mikkel Jørgensen
Mikkel Jørgensen 2018 年 12 月 22 日
コメント済み: madhan ravi 2018 年 12 月 22 日
Hi there.
I have been given a task, where i need to find the zeros of the following complex function:
roots.PNG
I have tried using fzero, but can't really make it work. I already know the answer to the task, which is that there are zeros in:
z er pi.PNG and in z er ikke pi.PNG
Do you guys know a way to make Matlab calculate this?
Thanks a lot!

回答 (2 件)

Star Strider
Star Strider 2018 年 12 月 22 日
If you want reasonably close results for the roots:
g = @(z) z.*exp(z)./((z-pi).*cos(z));
zv = linspace(-10, 10, 5000)*pi;
gz = g(zv);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
idxv = zci(gz);
for k1 = 1:numel(idxv)
b = [zv(idxv(k1)-1) 1; zv(idxv(k1)) 1] \ [gz(idxv(k1)-1); gz(idxv(k1))]; % Linear Fit Near Zero-Crossing
rt(k1) = -b(2)/b(1); % Interpolate To Precise Value
end
figure
plot(zv, g(zv))
hold on
plot(rt, zeros(size(rt)), 'xr')
hold off
grid
ylim([-5, 5])
fprintf('\nAs multiples of ‘pi’:\n')
fprintf('\t%8.2f\n', rt/pi)
fprintf('\nAs multiples of ‘n’:\n')
fprintf('\t%8.2f\n', (rt-pi/2)/pi)
Using fzero, the loop becomes:
for k1 = 1:numel(idxv)
rt(k1) = fzero(g, [zv(idxv(k1)-1),zv(idxv(k1)+1)]); % Use ‘fzero’ To Interpolate To Precise Value
end
with much more precise results.
It is likely not possible to do this without a loop, simply because it is necessary to iterate over all the zero-crossings.
  3 件のコメント
Star Strider
Star Strider 2018 年 12 月 22 日
Thanks! (Although ‘genius’ is probably something of an exaggeration!)
madhan ravi
madhan ravi 2018 年 12 月 22 日
:-)

サインインしてコメントする。


madhan ravi
madhan ravi 2018 年 12 月 22 日
編集済み: madhan ravi 2018 年 12 月 22 日
Use fsolve(), vpasolve() or solve() and ezplot() or fplot() to view where the zero occurs..
  2 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 22 日
Mikkel Jorgensen's answer moved here for consistency:
Hi. Thanks for the answer.
I just tried that - but am getting the wrong result. I have inserted a picture of what i have done:
madhan ravi
madhan ravi 2018 年 12 月 22 日
First thing that you need to know is uploading a picture is never useful.. upload your code
Second thing what do you observe from the graph?
Third thing why do you say the result is wrong?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by