필터 지우기
필터 지우기

Problem with plotting a semilog function

조회 수: 3 (최근 30일)
am
am 2019년 3월 27일
댓글: am 2019년 3월 27일
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--')

채택된 답변

Stephan
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])
resulting_plot.PNG
  댓글 수: 3
Stephan
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.
am
am 2019년 3월 27일
I thought the vector understood that automatically, and grew like a dynamic list? And I did not ned indexing? I nerver used indexing before in my plots.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by