Problem with plotting a semilog function
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I got help to solve syntax issues here (https://se.mathworks.com/matlabcentral/answers/452726-jacobain-with-3-functions) and go on.
I run that function once to get the result, saved it in variable x:ref and now I am trying to plot how the error decreases: I saved the number of iterations in an error vector and the norm in another vector and plot them against each other. It does not work iunfortunately!
f=@(x) [3.*x(1) - cos(x(2)*x(3)) - 3/2;
4.*x(1)^2 - 625.*x(2)^2 + 2.*x(3) - 1;
20.*x(3)^3 + exp(-1.*(x(1)*x(2))) + 9]
J=@(x) [3, x(3)*sin(x(2)*x(3)), x(2)*sin(x(2)*x(3));
8*x(1) , -1250*x(2), 2;
-x(2)*exp(-x(1)*x(2)), -x(1)*exp(-x(1)*x(2)), 60*x(3)^2]
TOL=1e-10;
h=inf;
x=[1;1;1];
error = []
iterations = []
iter = 0
x_ref= [0.8333, 0.0175, -0.7933]
TOL=1e-15;
h=inf;
x=[1;1;1];
while (norm(h)>TOL)
h=J(x)\f(x);
x=x-h;
norm(h);
end
h
x_ref=x;
h=inf;
x=[1;1;1];
iter = 0;
error = []
iterations = []
while (norm(h)>TOL)
h=J(x)\f(x);
x=x-h;
iter = iter + 1
iterations = iter
error = norm(x-x_ref)
end
%I tried to change the limits of the plot!
xlim([1 13])
ylim([1 10^17])
semilogy(iterations, error, 'r--')
0 件のコメント
採用された回答
Stephan
2019 年 3 月 27 日
編集済み: Stephan
2019 年 3 月 27 日
f=@(x) [3.*x(1) - cos(x(2)*x(3)) - 3/2;
4.*x(1)^2 - 625.*x(2)^2 + 2.*x(3) - 1;
20.*x(3)^3 + exp(-1.*(x(1)*x(2))) + 9]
J=@(x) [3, x(3)*sin(x(2)*x(3)), x(2)*sin(x(2)*x(3));
8*x(1) , -1250*x(2), 2;
-x(2)*exp(-x(1)*x(2)), -x(1)*exp(-x(1)*x(2)), 60*x(3)^2]
TOL=1e-10;
h=inf;
x=[1;1;1];
error = []
iterations = []
iter = 0
x_ref= [0.8333, 0.0175, -0.7933]
TOL=1e-15;
h=inf;
x=[1;1;1];
while (norm(h)>TOL)
h=J(x)\f(x);
x=x-h;
norm(h);
end
h
x_ref=x;
h=inf;
x=[1;1;1];
iter = 0;
error = []
iterations = []
while (norm(h)>TOL)
h=J(x)\f(x);
x=x-h;
iter = iter + 1
iterations(iter) = iter
error(iter) = norm(x-x_ref)
end
%I tried to change the limits of the plot!
semilogy(iterations, error, 'r--')
xlim([1 13])
ylim([10e-17 1])
3 件のコメント
Stephan
2019 年 3 月 27 日
The main problem was:
iterations(iter) = iter
error(iter) = norm(x-x_ref)
You did not saved the actual value of every iteration, but overwrited the values in every iteration.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!