Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Fixed Step Size
- syms x x_1 x_2 x_3
- f = [(x_1-4)^4;(x_2-3)^2;4*(x_3+5)^4];
- % Initial Variables
- epsilon = 10^(-3);
- x= [4;2;-1];
- alpha = 0.005;
- for (i=1:20)
- y1=diff(f(1),x_1);
- y2=diff(f(2),x_2);
- y3=diff(f(3),x_3);
- grad1=vpa(subs(y1,x(1)));
- grad2=vpa(subs(y2,x(2)));
- grad3=vpa(subs(y3,x(3)));
- gradf = [grad1;grad2;grad3];
- y = x - alpha*gradf;
- x = y;
- end
- x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement