フィルターのクリア

Numerical Solution

2 ビュー (過去 30 日間)
Abdulaziz
Abdulaziz 2012 年 5 月 29 日
Hi everybody,
I have an equation which is:
i*q=k*sin(q)
I need to use the matlab to find its roots. I want to set a specific values of k like (0.25, 0.5, 1, 2, 3) and find the values of q each time. Thanks in advance folks.

採用された回答

Teja Muppirala
Teja Muppirala 2012 年 6 月 22 日
Ok, your "q" will have an imaginary component, so you cannot use fzero directly. You can, however, solve it using fsolve, where you treat q as a 2-element vector containing the real and imaginary parts.
k = 4;
f = @(q) 1i.*[q(1) + 1i*q(2)]-k.*sin([q(1) + 1i*q(2)]);
x0 = [2; 0.5]
fsolve(@(q) norm(f(q)), x0)
This finds a zero at roughly [3; -0.7]. But since there are multiple minima, the result will depend on the initial conditions.
Note that you can make a plot of f, to visually see roughly where the zeros are. This will help you choose initial conditions.
k = 4;
f = @(q1,q2) 1i.*[q1 + 1i*q2]-k.*sin([q1 + 1i*q2]);
[Q1,Q2] = ndgrid(-10:.2:10);
surf(Q1,Q2, log(abs(f(Q1,Q2))));
  1 件のコメント
Teja Muppirala
Teja Muppirala 2012 年 6 月 22 日
Just as a note, instead of fsolve, fminsearch would work just as well.

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 5 月 29 日
fsolve() or fzero() or one of the minimizers.
  2 件のコメント
Abdulaziz
Abdulaziz 2012 年 6 月 21 日
Hi Walter,
Tried, tried, and tried, but totally confused. Could you please help me applying fsolve() or fzero() in my case
Thanks again
Walter Roberson
Walter Roberson 2012 年 6 月 22 日
fsolve() cannot deal directly with complex functions. Please see
http://www.mathworks.com/matlabcentral/answers/41458-fsolve-and-complex-solution

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


Image Analyst
Image Analyst 2012 年 6 月 21 日
Funny, I just copied the example from the help, and never having used fzero before myself, got the answer in about 5 seconds:
i=2 % Pick some sample values.
k=4
f = @(q)i.*q-k.*sin(q); % Replace example equation with Abdulaziz's
% Then find the zero near 2:
z = fzero(f,2)
z = 1.8955
  1 件のコメント
Abdulaziz
Abdulaziz 2012 年 6 月 22 日
hi,
I would like to thank you for helping me, but my i here is not a number it represents a complex number or component. Tried what you did, and this what I got:
k=4
f = @(q)1i.*q-k.*sin(q); % Replace example equation with Abdulaziz's
% Then find the zero near 2:
z = fzero(f,2)
k =
4
Error using fzero (line 309)
Function value at starting guess must be finite and real.

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

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by