From: Jason on
I am solving power flow problems and want to use matlab to solve for values. I would like to use a while loop to iterate until a certain error % is acheived. I have written code already however I have to manualy solve for the Jacobian {J term in the While loop}. Can Matlab compute the Jacobian inside a while loop? Here is the code that I have.

a=101.31/180*pi; %gama ij ~[degree/180 *pi] convert to radians for matlab

y=0; %1st guess delta 1 [in radians]
x=1; %1st guess V1
D=[y;x] %sets D vector for while loop


while(D(1)>0.001 || D(2)>0.001) % iterates till Error=0.0001
d=[y;x]; %inital guess matrix

p1=1.2 + x^2*1.92293 + x*9.8058*cos(y-a); % function p1
q1=0.3 +x^2*9.5153 + x*9.8058*sin(y-a); % function q1

z=[p1;q1] %p1 q1 in matrix form

J=[-x*9.8058*sin(y-a) x*2*1.92293+9.8058*cos(y-a);
x*9.8058*cos(y-a) x*2*9.5153+9.8058*sin(y-a)] %jacobian using Functions p1 and q1

J1=J^-1 %inverse jacobian

D=J1*z; %Produces the amount of error
D1=-J1*z %built in neg ~inverse J times P1 Q1 = delta delta 1 and delta v1

d1=d+D1 %Delta1 new{in radians} and V1 new to be used for next guess

y=d1(1); %y new guess
x=d1(2); %x new guess
end

Any Help would be great!
From: Nasser M. Abbasi on

"Jason " <jrk0002(a)uah.edu> wrote in message
news:he55or$pbr$1(a)fred.mathworks.com...
>I am solving power flow problems and want to use matlab to solve for
>values. I would like to use a while loop to iterate until a certain error
>% is acheived. I have written code already however I have to manualy solve
>for the Jacobian {J term in the While loop}. Can Matlab compute the
>Jacobian inside a while loop? Here is the code that I have.
>
> a=101.31/180*pi; %gama ij ~[degree/180 *pi] convert to radians for
> matlab
>
> y=0; %1st guess delta 1 [in radians]
> x=1; %1st guess V1
> D=[y;x] %sets D vector for while loop
>
>
> while(D(1)>0.001 || D(2)>0.001) % iterates till Error=0.0001
> d=[y;x]; %inital guess matrix
>
> p1=1.2 + x^2*1.92293 + x*9.8058*cos(y-a); % function p1
> q1=0.3 +x^2*9.5153 + x*9.8058*sin(y-a); % function q1
>
> z=[p1;q1] %p1 q1 in matrix form
>
> J=[-x*9.8058*sin(y-a) x*2*1.92293+9.8058*cos(y-a);
> x*9.8058*cos(y-a) x*2*9.5153+9.8058*sin(y-a)] %jacobian using Functions
> p1 and q1
>
> J1=J^-1 %inverse jacobian
>
> D=J1*z; %Produces the amount of error
> D1=-J1*z %built in neg ~inverse J times P1 Q1 = delta delta 1 and delta
> v1
>
> d1=d+D1 %Delta1 new{in radians} and V1 new to be used for next guess
>
> y=d1(1); %y new guess
> x=d1(2); %x new guess
> end
>
> Any Help would be great!

You could use the symbolic jacobian and when later you need to use it
numerically, use double() on it. (you might need to use subs on it as
needed)

--Nasser