How can I plot a graph according to the results
Afficher commentaires plus anciens
This is my code for find the minimum of a function using Newton's Method. Here I need to plot a graph according to the results. But I cannot figure out which parameters to use. Hope for a little help)
This is the example of the graph which I need.

Thank you.
clc
clear
%Newton method
func = @(x) 10.*x(1).^2 - 4.*x(1).*x(2) + 7.*x(2).^2 - 4.* sqrt5 (5.*x(1) - x(2)) - 16 ;
e = 0.01;
i=0;
n=0;
b = [-20*sqrt(5); 4*sqrt(5)];
x =[0 10]';
[H,antiGrad,F]=QF(x(1),x(2));
n = n + 7;
norm_aG = norm(antiGrad);
Xmin=-inv(H)*b;
Points(:,i+1)=x;
funcvalues(1)=F;
while(norm_aG > e)
i=i+1;
del=linsolve(H,antiGrad);
x=x+del;
[H,antiGrad,F]=QF(x(1),x(2));
n=n+7;
norm_aG=norm(antiGrad);
Points(:,i+1)=x;
funcvalues(i+1)=F;
end
fprintf('Precision parameter %.4f\n',e);
fprintf('Point of minimum [%.4f ,%.4f]\n', x(1),x(2));
fprintf('Min: %10.4f \n', F);
fprintf('Iterations: %d \n',i );
fprintf('Number of calculated objective function values: %d\n\n',n );
% drawGraph(Xmin, Points, func);
function [H,antiGrad,I]=QF(x,y)
derivative_x = 20*x - 4*y - 20*sqrt(5);
derivative_y = - 4*x + 14*y + 4*sqrt(5);
antiGrad = -[derivative_x,derivative_y]';
H = [20 -4 ; -4 14];
I = x.^2.*10 + 4.*x.*y + 7.*y.^2 - 4.*sqrt(5).*(5*x-y) - 16;
%contour(x, y, I, func,'r', 'showText', 'on');
%plot(Points(1,:), Points(2, :), 'g-*');
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
