FSOLVE GIVES SAME VALUE

2 vues (au cours des 30 derniers jours)
JYOTI PRAKASH BEHERA
JYOTI PRAKASH BEHERA le 27 Nov 2020
Réponse apportée : Matt J le 27 Nov 2020
clc;clearvars;close all; format short g;format compact;
tfinal=30;
pars.D=0.00005611;
pars.x2f=20;
pars.Y=0.4;
pars.beta=0.000055;
pars.k1=0.04545;
pars.alpha=2.2;
pars.mumax=0.000133;
pars.km=1.2;
pars.x3max=50;
csol2=fsolve(@(c) chemofun(c,pars),[5 4.5 15]);
function f=chemofun(c,pars)
f=zeros(3);
x1=c(1);
x2=c(2);
x3=c(3);
mumax=pars.mumax;
x3max=pars.x3max;
km=pars.km;
k1=pars.k1;
mu=((mumax)*x2*(1-(x3/(x3max))))/(km+x2+(x2^2)*(k1));
D=pars.D;
x2f=pars.x2f;
Y=pars.Y;
A=pars.alpha;
B=pars.beta;
f(1)=(mu-(D));
f(2)=(D)*(x2f-x2)-(mu*x1)/(Y);
f(3)=(-1)*(D)*x3+((A)*mu+B)*x1;
end
  4 commentaires
JYOTI PRAKASH BEHERA
JYOTI PRAKASH BEHERA le 27 Nov 2020
Mu have x1
Alan Stevens
Alan Stevens le 27 Nov 2020
Actually, it seems to have x2 and x3; but you are right, three equations are involved. The results seem very sensitive to the initial guesses though.

Connectez-vous pour commenter.

Réponses (1)

Matt J
Matt J le 27 Nov 2020
clc;clearvars;close all; format short g;format compact;
tfinal=30;
pars.D=0.00005611;
pars.x2f=20;
pars.Y=0.4;
pars.beta=0.000055;
pars.k1=0.04545;
pars.alpha=2.2;
pars.mumax=0.000133;
pars.km=1.2;
pars.x3max=50;
fun=@(c) chemofun(c,pars);
opts=optimoptions('fsolve','StepTolerance',1e-12,'FunctionTolerance',1e-12,'OptimalityTolerance',1e-12);
[csol2,fsol2]=fsolve(fun,[5 4.5 15],opts)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
csol2 = 1×3
5.9905 5.0238 19.051
fsol2 = 1×3
-8.9331e-12 1.1261e-10 -9.9097e-11
function f=chemofun(c,pars)
f=zeros(1,3); %<-------
x1=c(1);
x2=c(2);
x3=c(3);
mumax=pars.mumax;
x3max=pars.x3max;
km=pars.km;
k1=pars.k1;
mu=((mumax)*x2*(1-(x3/(x3max))))/(km+x2+(x2^2)*(k1));
D=pars.D;
x2f=pars.x2f;
Y=pars.Y;
A=pars.alpha;
B=pars.beta;
f(1)=(mu-(D));
f(2)=(D)*(x2f-x2)-(mu*x1)/(Y);
f(3)=(-1)*(D)*x3+((A)*mu+B)*x1;
end

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by