Jacobian Function in MATLAB

8 Ansichten (letzte 30 Tage)
Mckale Grant
Mckale Grant am 17 Mär. 2022
Bearbeitet: Torsten am 18 Mär. 2022
I'm trying to run the function below, but I'm getting the following message when I try to run it
When the m file is named Jacobian: Unrecognized function or variable 'M3'
When the m file is named MidtermProject_concentrations: Not enough input arguments.
Error in MidtermProject_concentrations (line 76)
f6P3 = -Q3-k4*(M3*V3)^n*V3;
function J = Jacobian(M3, P3)
Jacobian = zeros(15,15); % 15 unknowns
% Volumetric flowrate (L/min)
QA_in = 0.15;
QM_in = 0.04;
Qcyc_in = 0.04; % Only A, B, and P (L/min)
QP_out = 0.07; % Only PMn and M
QAB_out = 0.12; % Only A and B
Qcyc_out = 0.04; % Only A, B, and P
Q1 = QA_in+Qcyc_in;
Q2 = QM_in;
Q3 = Q1+Q2;
Q4 = QP_out;
Q5 = QAB_out;
Q6 = Qcyc_in;
Q7 = Qcyc_out;
% Rate constants
k1 = 0.0147; % Forward rate (1/min)
k_1 = 0.0360; % Backward rate (1/min)
k2 = 0.0471; % Forward rate (1/min)
k_2 = 0.0038; % Backward rate (1/min)
k3 = 0.0033; % Forward rate(1/min)
k_3 = 0.0065; % Backward rate (1/min)
k4 = 1.574507; % Forward rate (kg^-n/min)
% Mass concentration (kg/L)
CA_in = [0.01 0.03 0.036 0.05 0.07 0.09];
CM_in = 0.151;
deltaCA = -0.530462;
% Other constants
V1 = 10; % Volume in L
V2 = 30; % Volume in L
V3 = 5; % Volume in L
V4 = 5; % Volume in L
n = 2.500215; % Reaction order
tau = [1 5 10 15]; % residence time (min)
% Unit 1: Isomerization Chamber (well-mixed vessel)
f1A1 = -Q1-k1*V1-k_3*V1;
f1B1 = k_1*V1;
f1P1 = k3*V1;
f1A7 = Q7;
Jacobian(1,1) = f1A1;
Jacobian(1,2) = f1B1;
Jacobian(1,3) = f1P1;
Jacobian(1,14) = f1A7;
f2A1 = k1*V1;
f2B1 = -Q2-k_1*V1-k2*V1;
f2P1 = k_2*V1;
f2B7 = Q7;
Jacobian(2,1) = f2A1;
Jacobian(2,2) = f2B1;
Jacobian(2,3) = f2P1;
Jacobian(2,15) = f2B7;
f3A1 = k_3*V1;
f3B1 = k2*V1;
f3P1 = -Q1-k_2*V1-k3*V1;
f3P6 = Q7;
Jacobian(3,1) = f3A1;
Jacobian(3,2) = f3B1;
Jacobian(3,3) = f3P1;
Jacobian(3,13) = f3P6;
% Unit 2: mAb Binding Chamber
f4A1 = Q1;
f4A3 = -Q3;
Jacobian(4,1) = f4A1;
Jacobian(4,4) = f4A3;
f5B1 = Q1;
f5B3 = Q3;
Jacobian(5,2) = f5B1;
Jacobian(5,5) = f5B3;
f6P1 = Q1;
f6P3 = -Q3-k4*(M3*V3)^n*V3;
f6M3 = -k4*n*M3^(n-1)*V3^(n+1)*P3;
Jacobian(6,3) = f6P1;
Jacobian(6,6) = f6P3;
Jacobian(6,7) = f6M3;
f7P3 = -k4*(M3*V4)^n*V4;
f7M3 = -Q3-k4*n*M3^(n-1)*V4^(n+1)*P3;
Jacobian(7,6) = f7P3;
Jacobian(7,7) = f7M3;
f8P3 = k4*(M3*V4)^n*V4;
f8M3 = k4*n*M3^(n-1)*V4^(n+1)*P3;
f8PMn3 = -Q3;
Jacobian(8,6) = f8P3;
Jacobian(8,7) = f8M3;
Jacobian(8,8) = f8PMn3;
% Unit 3: Protein Affinity Column
f9A3 = Q3-Q6;
f9A5 = -Q5;
Jacobian(9,4) = f9A3;
Jacobian(9,11) = f9A5;
f10B3 = Q3-Q6;
f10B5 = -Q5;
Jacobian(10,5) = f10B3;
Jacobian(10,12) = f10B5;
f11P3 = Q3;
f11P6 = -Q6;
Jacobian(11,6) = f11P3;
Jacobian(11,13) = f11P6;
f12M3 = Q3;
f12M4 = -Q4;
Jacobian(12,7) = f12M3;
Jacobian(12,9) = f12M4;
f13PMn3 = Q3;
f13PMn4 = -Q4;
Jacobian(13,8) = f13PMn3;
Jacobian(13,10) = f13PMn4;
% Unit 4: A-->B Conversion Reactor
f14A3 = Q6+Q6*deltaCA;
f14A7 = -Q7;
Jacobian(14,4) = f14A3;
Jacobian(14,14) = f14A7;
f15A3 = -Q6*deltaCA;
f15B3 = Q6;
f15B7 = -Q7;
Jacobian(15,4) = f15A3;
Jacobian(15,5) = f15B3;
Jacobian(15,15) = f15B7;
end
  3 Kommentare
Mckale Grant
Mckale Grant am 18 Mär. 2022
I tried specifying M3 and P3 but I still got the same error
Torsten
Torsten am 18 Mär. 2022
Bearbeitet: Torsten am 18 Mär. 2022
Matt is right.
To avoid too many changes, replace the title line
function J = Jacobian(M3, P3)
by
function Jacobian = Jac(M3, P3)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J
Matt J am 18 Mär. 2022
Bearbeitet: Matt J am 18 Mär. 2022
Do not give variables the same name as the function they are declared in. You have a variable named 'Jacobian' inside a function with that same name.

Community Treasure Hunt

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

Start Hunting!

Translated by