Plot how would I take my out put C(2) and plot it vs Al (Alpha) This newtons method works to get Ca2 and CA1, but I want to bang CA2 vs Alpha for alpha 0-1. Do I use a matrix?

1 次查看(过去 30 天)
function TEST11
clear
n=2;
Jac=zeros(n); fv=zeros(n,1); f=zeros(n,1); Cd=zeros(n,1); C=zeros(n,1);
C=[0.5; 0.3;];
CA0=1; V=1; Q=50; k1=1; k2=1; al=0.11;
Rel_dx=0.01;
itr_max=100; tol=10^-4;
for k=1:itr_max
Jac=J(C);
fv=fx(C);
f=-1.*fv';
d=Jac\f;
C=C+d;
Rerr=d./C;
max_err=max(abs(Rerr));
fprintf('CA1=%f & CA2=%f max error=%f\n',C,max_err)
if max_err<tol; break; end;
end
if k==itr_max
fprintf('Newtons method failed to converge in %d iternations\n', itr_max)
end
if i<itr_max
fprintf('The solution is CA1=%f CA2=%f in %d iterations\n', C,k)
end
function Jac=J(C)
fv=fx(C);
for j=1:n
C(j)=C(j)*(1+Rel_dx);
fvd=fx(C);
for i=1:n
Jac(i,j)=(fvd(i)-fv(i))/C(j)/Rel_dx;
end
C(j)=C(j)/(1+Rel_dx);
end
end
function fv=fx(C)
fv(1)=Q*CA0-Q*C(1)-k1*C(1)^2*(al*V);
fv(2)=Q*C(1)-Q*C(2)-k2*C(2)^2*(1-al)*V;
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by