Assignment 1
Assignment 1
Assignment 1
>> a0=5;
>> a1(1)=4;
>> a2(1)=3;
>> a3(1)=2;
>> a4(1)=1;
>> beta=5;
>> a5=0.5;
>> j=1;
>> a0=5;
>> a1(1)=4.5;
>> a2(1)=4;
>> a3(1)=3.5;
>> a4(1)=3;
>> a5(1)=2.5;
>> a6(1)=2;
>> a7(1)=1.5;
>> a8(1)=1;
>> a9(1)=0.8;
>> a10=0.5;
>> beta=5;
>> x=[a1(1); a2(1); a3(1); a4(1); a5(1); a6(1); a7(1); a8(1); a9(1); beta(1)];
>> jacobian=[
2*beta(1)*a1(1)+1 0 0 0 0 0 0 0 0 a1(1)^2;
-1 2*beta(1)*a2(1)+1 0 0 0 0 0 0 0 a2(1)^2;
0 -1 2*beta(1)*a3(1)+1 0 0 0 0 0 0 a3(1)^2;
0 0 -1 2*beta(1)*a4(1)+1 0 0 0 0 0 a4(1)^2;
0 0 0 -1 2*beta(1)*a5(1)+1 0 0 0 0 a5(1)^2;
0 0 0 0 -1 2*beta(1)*a6(1)+1 0 0 0 a6(1)^2;
0 0 0 0 0 -1 2*beta(1)*a7(1)+1 0 0 a7(1)^2;
0 0 0 0 0 0 -1 2*beta(1)*a8(1)+1 0 a8(1)^2;
0 0 0 0 0 0 0 -1 2*beta(1)*a9(1)+1 a9(1)^2;
0 0 0 0 0 0 0 0 -1 a10^2;
];
>> y=[
beta(1)*a1(1)^2-(a0-a1(1));
beta(1)*a2(1)^2-(a1(1)-a2(1));
beta(1)*a3(1)^2-(a2(1)-a3(1));
beta(1)*a4(1)^2-(a3(1)-a4(1));
beta(1)*a5(1)^2-(a4(1)-a5(1));
beta(1)*a6(1)^2-(a5(1)-a6(1));
beta(1)*a7(1)^2-(a6(1)-a7(1));
beta(1)*a8(1)^2-(a7(1)-a8(1));
beta(1)*a9(1)^2-(a8(1)-a9(1));
beta(1)*a10^2-(a9(1)-a10)];
Assignment-1:
CSTR reactor in series, solve non-linear equation using Matlab
Prepared by: Faisal Mumtaz
>> j=1;
jacobian = [
2*beta(j)*a1(j)+1 0 0 0 0 0 0 0 0 a1(j)^2;
-1 2*beta(j)*a2(j)+1 0 0 0 0 0 0 0 a2(j)^2;
0 -1 2*beta(j)*a3(j)+1 0 0 0 0 0 0 a3(j)^2;
0 0 -1 2*beta(j)*a4(j)+1 0 0 0 0 0 a4(j)^2;
0 0 0 -1 2*beta(j)*a5(j)+1 0 0 0 0 a5(j)^2;
0 0 0 0 -1 2*beta(j)*a6(j)+1 0 0 0 a6(j)^2;
0 0 0 0 0 -1 2*beta(j)*a7(j)+1 0 0 a7(j)^2;
0 0 0 0 0 0 -1 2*beta(j)*a8(j)+1 0 a8(j)^2;
0 0 0 0 0 0 0 -1 2*beta(j)*a9(j)+1 a9(j)^2;
0 0 0 0 0 0 0 0 -1 a10^2;
]
y=[
beta(j)*a1(j)^2-(a0-a1(j));
beta(j)*a2(j)^2-(a1(j)-a2(j));
beta(j)*a3(j)^2-(a2(j)-a3(j));
beta(j)*a4(j)^2-(a3(j)-a4(j));
beta(j)*a5(j)^2-(a4(j)-a5(j));
beta(j)*a6(j)^2-(a5(j)-a6(j));
beta(j)*a7(j)^2-(a6(j)-a7(j));
beta(j)*a8(j)^2-(a7(j)-a8(j));
beta(j)*a9(j)^2-(a8(j)-a9(j));
beta(j)*a10^2-(a9(j)-a10)];
x = x - jacobian^-1*y;
a1(j+1) = x(1);
a2(j+1) = x(2);
a3(j+1) = x(3);
a4(j+1) = x(4);
a5(j+1) = x(5);
a6(j+1) = x(6);
a7(j+1) = x(7);
a8(j+1) = x(8);
a9(j+1) = x(9);
beta(j+1) = x(10);
j=j+1;
end