Help to solv a equation with iteration

7 ビュー (過去 30 日間)
Claus Madsen
Claus Madsen 2013 年 3 月 8 日
I need help, how do i make a code in matlab for iterate the following eq:
x=0.46-0.5*cos(3.14*(y/d))+0.004*cos(2*3.14*(y/d))
where y is the only unknown constant? i know the value of x and d.
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 8 日
What do you mean?

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

採用された回答

Youssef  Khmou
Youssef Khmou 2013 年 3 月 9 日
hi Clauss,
there are many ways to solve the equation, but with iterations i have few ideas : there is a method called Bisection :
d=1.3; % I SUPPOSED d=1.3
f=@(y) 0.46-0.5*cos(3.14*(y/d))+0.004*cos(2*3.14*(y/d))
format long
eps_abs = 1e-5;
eps_step = 1e-5;
a = 70.0; % Initial Guess to your function such that f(a)>0.
b = 78.0; % Initial Guess to your function such that f(b)<0.
while (b - a >= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs ) )
c = (a + b)/2;
if ( f(c) == 0 )
break;
elseif ( f(a)*f(c) < 0 )
b = c;
else
a = c;
end
end
  2 件のコメント
Claus Madsen
Claus Madsen 2013 年 3 月 10 日
編集済み: Claus Madsen 2013 年 3 月 10 日
thanks for the answer. Im quit new in matlab, is this the most simple way to iterate? And it do not work if i change the value of d?
Claus Madsen
Claus Madsen 2013 年 3 月 10 日
From what i can understand this solve the eq for f(c)=0 but as i wrote in my problem, i know what x is, and its not 0 but 0.2?

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

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2013 年 3 月 9 日
編集済み: Roger Stafford 2013 年 3 月 9 日
You can solve that equation without doing any iteration, Claus. Using the formula
cos(2*A) = 2*cos(A)^2-1
your equation is equivalent to
.008*cos(3.14*y/d)^2-.5*cos(3.14*y/d)+.456-x = 0
and this is a quadratic equation in cos(3.14*y/d) which you can solve for. You will then have the unknown y expressed as d/3.14 times the arccosine of the two possible roots of this quadratic. (I presume 3.14 is your approximation for pi.) Provided either of these roots lie between -1 and +1, this will give you an infinite number of possible real-valued solutions for y.

カテゴリ

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