why my iteration prog doesn't work ?
古いコメントを表示
% Use NR method f(x)= x^3-5x^2+7x-3
clc
TV=3;
x=(4);
tol=0.0007;
format long
for i=1:5;
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
x(i+1)=(x(i))-(fx/fxx);
E_T(i)=(abs((TV-x(i+1))/TV))*100;
end
for i=1:5;
e(i)=(x(6))-(x(i));
fx=(x(i))^3-5*(x(i))^2+7*(x(i))-3;
fxx=3*(x(i))^2-10*(x(i))+7;
fxxx=6*(x(i))-10;
e(i+1)=(-fxxx/2*fxx)*(e(i))^2;
end
if abs(TV-(x(i+1)))<tol
disp(' enough to here')
disp(' -----------')
disp(' x(i+1) ')
disp(' -----------')
x;
disp(' -----------')
disp(' T.V ')
disp(' -----------')
E_T;
disp(' -----------')
disp(' E(i+1) ')
disp(' -----------')
e;
disp(' ------------- ')
end
%-----------------------------------------------------------
7 件のコメント
John D'Errico
2017 年 1 月 23 日
編集済み: John D'Errico
2017 年 1 月 23 日
Sure it works. It does exactly what it does. Of course, we don't know what you want it to do, since you don't tell us.
If we could actually read it, we might be more willing to help you. So why not learn to format your code as code?
Edit the question. Select the block of text that is code, then click on the "{} Code" button above the edit window. Your code will now be readable as code.
Then tell us what the code does wrong. Do you get an error? Does it just return the wrong thing? What do you expect it to do?
If you want help from people, then why not make it possible for people to give you help?
KSSV
2017 年 1 月 23 日
What is that not working here?
khalid boureeny
2017 年 1 月 23 日
編集済み: Walter Roberson
2017 年 1 月 23 日
khalid boureeny
2017 年 1 月 23 日
Walter Roberson
2017 年 1 月 23 日
That is an efficiency warning; it is telling you that your code could possibly be made faster. It is not an error message. You could get rid of it by starting out with
E_T = zeros(1,5);
khalid boureeny
2017 年 1 月 25 日
編集済み: Walter Roberson
2017 年 1 月 25 日
Walter Roberson
2017 年 1 月 25 日
If you need 50 or 80 digits you will need to switch to the Symbolic Toolbox, and display using vpa()
NumDig = 50;
x = sym(-0.1);
y = sym(0);
fprintf(' i x \n')
fprintf(' --- ------------- \n')
for i=1:5;
fx=(x(i))^3-(x(i))^2+2;
fxx=3*(x(i))^2-2*(x(i));
y(i)=x(i)-(fx/fxx);
fy=(y(i))^3-(y(i))^2+2;
fyy=3*(y(i))^2-2*(y(i));
x(i+1)=x(i)+([fy-fx]/fyy);
end
for i=1:length(x)
fprintf('%2i %s\n', i, char(vpa(x(i),NumDig)))
end
採用された回答
その他の回答 (1 件)
Lateef Adewale Kareem
2017 年 1 月 23 日
0 投票
increase your number of iteration, you will meet the tolerance target
カテゴリ
ヘルプ センター および File Exchange で Special Values についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!