Solving Equations in MATLAB

2 ビュー (過去 30 日間)
trythisone noone
trythisone noone 2020 年 12 月 27 日
コメント済み: Ameer Hamza 2020 年 12 月 28 日
Hello,
I have the following equation.
cos(x) == 0
I want to get two or more possible solutions for the above equation which are 90, 270, and so on. The solve function returns the first solution only.
This technique is important for me to calculate the antenna beamwidths. Any ideas?
Thanks in Adv

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 27 日
編集済み: Ameer Hamza 2020 年 12 月 27 日
There is no general solution to such a problem. A common way is to specify several starting points for the numerical solver and find the unique solutions.
y = @(x) cos(x);
x_range = 0:0.1:4*pi;
y_sol = zeros(size(x_range));
for i = 1:numel(x_range)
y_sol(i) = fzero(y, x_range(i));
end
y_sol = uniquetol(y_sol)
  2 件のコメント
trythisone noone
trythisone noone 2020 年 12 月 27 日
Wow, Nice trick man. It works fine. <3
Ameer Hamza
Ameer Hamza 2020 年 12 月 28 日
I am glad to be of help!

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 12 月 27 日
SOME problems can be handled to find all solutions.
syms x
>> xsol = solve(cos(x) == 0,'returnconditions',true)
xsol =
struct with fields:
x: [1×1 sym]
parameters: [1×1 sym]
conditions: [1×1 sym]
>> xsol.parameters
ans =
k
>> xsol.conditions
ans =
in(k, 'integer')
>> xsol.x
ans =
pi/2 + pi*k
So we learn the set of all solutions takes the form
x = pi/2 + pi*k
where k is an integer.
Sadly, a fully general solution to many problems will not be written so easily. But you can always try.

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by