フィルターのクリア

Newton's method(calculating theta)

4 ビュー (過去 30 日間)
Ahmed Alhawaj
Ahmed Alhawaj 2020 年 3 月 16 日
回答済み: Sriram Tadavarty 2020 年 3 月 16 日
w = 30; h = 30; b = 3.5; % In inches
f = @(theta) w*sind(theta) - h*cosd(theta) - b;
fp = @(theta) w*cosd(theta)+h*sind(theta);
theta_newt(1) = 49.76; % Set initial guess
tol=0.4771;
n=1;
while n<=1:50
fe = f(theta_newt(1));
fpe = fp(theta_newt(1));
theta_newt(n+1) = theta_newt(n) - fe(n)/fpe(n);
if theta_newt(n+1)< 49.73-tol || theta_newt(n+1)>49.73+tol
return
else
theta=theta_newt(n+1);
end
n=n+1;
end
disp(theta)
why is the code not returning to the loop when it is not calculating the wanted angle?

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 16 日
Hi Ahmed,
The condition you placed for the while loop is a series of vector. Update the condition as below and code requires minor modifications to work
while n <= 50 % It runs the loop till n becomes 50
fe = f(theta_newt(n));
fpe = fp(theta_newt(n));
theta_newt(n+1) = theta_newt(n) - fe/fpe;
if theta_newt(n+1)< 49.73-tol || theta_newt(n+1)>49.73+tol
return
else
theta=theta_newt(n+1);
end
n=n+1;
end
Hope this helps.
Regards,
Sriram

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by