Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jacobian Algorithm

Status
Not open for further replies.

samlee2006

Electrical
Joined
Dec 10, 2005
Messages
1
Location
US
I am trying to write a program in matlab to find Jaobian for any test function. As an example I am trying on Rosenbrock function and ,I think there is a minor error in the way I am defining the jacobian.
I highly appreciate if you would have a look at my Jacobian algorithm and let me know how I can change it so it will work.
-------------------------------------------------------------
rosenbrock function for 2n variables.

%rosenbrock function for 2n variables.

%function [fx] = rosenbrock(x)
function [Fx] = jrosenbrock(x)
x=[-1.2,1];

n = length(x);
fx =0 ;
Fx=[];
for i =2:2:n

f_x(i-1)=10*(x(i) - x(i-1)^2);
f_x(i)= (1-x(i-1));
%afx = 100*(x(i) - x(i-1)^2)^2 + (1-x(i-1))^2;
fx= (f_x(i-1))^2+(f_x(i))^2;


Fx=f_x';
Fx
end

-----------------------------------------------------------------------------------------------------------------------JACOBIAN CODE
epsi= sqrt(macepsi);
%fx=@rosenbrock;
Fx=@rosenbrock;
x=[-1.2 1];
%feval(fx,x);
%Fofx = feval(Fx,x);
n = length(Fx)
Jx =[];
for i = 1:n
delta = x
delta(i) = x(i)+ epsi;

for j=1:n;
%feval(Fx,delta);
%Fdelta= Fx;

Jx(j,i)= (feval(Fx,delta)- feval(Fx,x))/epsi;
end
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top