Also when I go through debugging, the function kinetics123 reads all of the input in correctly.
Ahora está siguiendo esta pregunta
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
Too Many Input Arguments
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello! I've checked my code multiple times, and I keep getting a "too many inputs" error. Would anyone be able to help?
function b = kinetics123(v)
k1 = v(1);
k2 = v(2);
k3 = v(3);
k4 = v(4);
k5 = v(5);
b =(k1*k3*102*sqrt(k2*100)*0.0008*(1+k1*102+sqrt(k2*100)+(k3/k4)*k1*102*(0.609/k5))^2 - (6.1*10^-5));
end
v = [0.1, 0.1, 0.1, 0.1, 0.1];
options = optimset('MaxFunEvals',1000);
q = fminsearchbnd(@kinetics123, v, [], [], options)
Error using kinetics123
Too many input arguments.
Error in fminsearchbnd>@(x,varargin)fun(xtransform(x),varargin{:}) (line 233)
intrafun = @(x, varargin) fun(xtransform(x), varargin{:});
Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:})
1 comentario
Madeline Alzamora
el 21 de Nov. de 2021
Respuesta aceptada
Star Strider
el 21 de Nov. de 2021
This works (with and without the norm call) —
v = [0.1, 0.1, 0.1, 0.1, 0.1];
[B,fv] = fminsearch(@kinetics123, v) % Without 'norm'
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: -21938913608024237095924990053658057124452464574261387201643260652167428249316775121043664379710237162164047785759422273482999418904150474824722563045423035223507880578537363894487937679396863294586303477699253665349954558661450752149220753408.000000
B = 1×5
1.0e+53 *
-1.3634 0.3493 0.0546 0.4180 0.2841
fv = -2.1939e+241
[B,fv] = fminsearch(@(b)norm(kinetics123(b)), v) % With 'norm'
B = 1×5
-0.0111 0.0804 0.0890 0.1668 0.1356
fv = 6.1002e-05
function b = kinetics123(v)
k1 = v(1);
k2 = v(2);
k3 = v(3);
k4 = v(4);
k5 = v(5);
b =(k1*k3*102*sqrt(k2*100)*0.0008*(1+k1*102+sqrt(k2*100)+(k3/k4)*k1*102*(0.609/k5))^2 - (6.1*10^-5));
end
Adding the norm call (finds the minimum greater than sero) produces different parameter estimates. The code runs without error either way here.
I have no idea what the code is su0pposed to do otherwise.
.
10 comentarios
Madeline Alzamora
el 21 de Nov. de 2021
This helps a lot! I'm basically trying to do a fit for kinetic parameters and output the constants that make the system zero.
Thank you!!
Star Strider
el 21 de Nov. de 2021
My pleasure!
That’s what I thought.
Are they being fitted to data? If so, uploading-posting that data here (preferably as a text or spreadsheet file) would allow me to help fit it to the equations.
Right now, I’m not certain what the objective is, other than to minimise the norm of the function (so I would advise using the version with the norm call).
.
Madeline Alzamora
el 21 de Nov. de 2021
Hi! Here's my data :)
I straight up just used the first values when i was computing the constants because I wasn't sure how to do a for loop for fmin search. with 102 = acetone, 0.609 = isopropanol out, and (6.1*10^-5) = experimental rate. I'm also attaching the edits that I made to the code based on a personal typing error and setting a lower bound. My v values are complete guesses, and the final answers keep changing whenever I guess them. Is that supposed to happen?
You're the best!!
function b = kinetics123(v)
%I know that all of the rate constants should be positive, and k3 should
%theoretically be the smallest because it is the rate limiting step
k1 = v(1);
k2 = v(2);
k3 = v(3);
k4 = v(4);
k5 = v(5);
%broke it into steps so I could read it clearer when typing
c = k1*k3*102*sqrt(100*k2)*0.0008; %100 and 0.0008 are set values, 102 is ac in excel
f = (1+k1*102+sqrt(k2*100) + (0.609/k5))^2; %102 is ac in excel, 0.609 is iso in excel
b = c/f - (6.1*10^-5);
%though there are more values, the experimental rate doesn't change too
%much
end
v = [1, 1, 1, 1, 1];
kinetics123(v);
A = [];
b= [];
Aeq = [];
beq = [];
[B,fv] = fmincon(@kinetics123, v, A, b, Aeq, beq, [0 0 0 0 0], [])
Star Strider
el 21 de Nov. de 2021
It is difficult for me to follow that, because it is not obvious to me how to apply the data to the regression equations.
What kinetic equation (or equations) is the system modeling?
Are they differential equations or functions (analytically inetgrated differential equations)?
.
Madeline Alzamora
el 21 de Nov. de 2021
Sorry!! I'm trying to model equation "b", and it should be a function. I just combined it into a few steps because I was having a difficult time making sure that all of my parenthesis were in the same place.
The three changing variables are acetone (102 here), the change in isopropanol (0.609 here), and the total rate is the output. I derived this function by hand based on theoretical mechanisms provided in my problem statement.
Star Strider
el 21 de Nov. de 2021
Thank you!
This runs without error. I’m not certain what ‘total rate’ is (there’s no specific variable with that name), so substitute that in the ‘TotalRate’ variable I created if mine isn’t correct. I need to know what it is so that I can experiment with it
Data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/808424/kinetics%20project.xlsx', 'VariableNamingRule','preserve')
Data = 400×17 table
Acetone in Iso out R_Iso_exp R_Iso_mech Sq Diff Var6 Acetone in_1 Iso out_1 R_Iso_exp_1 R_Iso_mech_1 Sq Diff_1 Var12 Acetone in_2 Iso out_2 R_Iso_exp_2 R_Iso_mech_2 Sq Diff_2
__________ _______ __________ __________ _______ ____ ____________ _________ ___________ ____________ _________ _____ ____________ _________ ___________ ____________ _________
102 0.61038 6.118e-05 NaN NaN NaN 102 3.5818 0.00028721 NaN NaN NaN 102 4.7952 0.00032042 NaN NaN
104 0.60501 6.0642e-05 NaN NaN NaN 104 3.5881 0.00028771 NaN NaN NaN 104 4.8352 0.0003231 NaN NaN
106 0.5992 6.006e-05 NaN NaN NaN 106 3.6137 0.00028977 NaN NaN NaN 106 4.8849 0.00032642 NaN NaN
108 0.59493 5.9632e-05 NaN NaN NaN 108 3.6297 0.00029105 NaN NaN NaN 108 4.9199 0.00032876 NaN NaN
110 0.5903 5.9167e-05 NaN NaN NaN 110 3.6417 0.00029201 NaN NaN NaN 110 4.9597 0.00033141 NaN NaN
112 0.58668 5.8804e-05 NaN NaN NaN 112 3.6558 0.00029315 NaN NaN NaN 112 5.0024 0.00033427 NaN NaN
114 0.58086 5.8222e-05 NaN NaN NaN 114 3.6619 0.00029363 NaN NaN NaN 114 5.0438 0.00033704 NaN NaN
116 0.57643 5.7777e-05 NaN NaN NaN 116 3.6763 0.00029479 NaN NaN NaN 116 5.0806 0.00033949 NaN NaN
118 0.57281 5.7414e-05 NaN NaN NaN 118 3.6839 0.0002954 NaN NaN NaN 118 5.1134 0.00034168 NaN NaN
120 0.56897 5.7029e-05 NaN NaN NaN 120 3.6948 0.00029627 NaN NaN NaN 120 5.157 0.0003446 NaN NaN
122 0.56303 5.6434e-05 NaN NaN NaN 122 3.7038 0.000297 NaN NaN NaN 122 5.178 0.000346 NaN NaN
124 0.5581 5.594e-05 NaN NaN NaN 124 3.7137 0.00029778 NaN NaN NaN 124 5.214 0.00034841 NaN NaN
126 0.55447 5.5576e-05 NaN NaN NaN 126 3.735 0.0002995 NaN NaN NaN 126 5.2546 0.00035112 NaN NaN
128 0.55023 5.5151e-05 NaN NaN NaN 128 3.7462 0.00030039 NaN NaN NaN 128 5.2993 0.00035411 NaN NaN
130 0.54616 5.4743e-05 NaN NaN NaN 130 3.7468 0.00030044 NaN NaN NaN 130 5.3328 0.00035635 NaN NaN
132 0.54246 5.4372e-05 NaN NaN NaN 132 3.762 0.00030166 NaN NaN NaN 132 5.3578 0.00035801 NaN NaN
Reactants = [Data.('Acetone in') Data.('Iso out')];
TotalRate = sum(Reactants,2);
% v = [0.1, 0.1, 0.1, 0.1, 0.1];
v = rand(5,1);
[B,fv] = fminsearch(@(b)norm(TotalRate - kinetics123(b,Reactants)), v)
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 1002.894706
B = 5×1
0.0007
0.1608
1.3782
0.0005
0.3635
fv = 1.0029e+03
EstTotalRate = kinetics123(B,Reactants);
EstTotalRate = 400×1
33.8815
35.2729
36.6236
38.1728
39.6947
41.3730
42.7589
44.3520
46.0861
47.8085
figure
scatter3(Reactants(:,1), Reactants(:,2), TotalRate, 50, 'p', 'filled')
hold on
plot3(Reactants(:,1), Reactants(:,2), EstTotalRate, '-r')
hold off
grid on
xlabel('CH_3CHO')
ylabel('CH_3CH_2OH')
zlabel('Output')
legend('Data', 'Fitted Regression', 'Location','best')
function b = kinetics123(v,Reactants)
k1 = v(1);
k2 = v(2);
k3 = v(3);
k4 = v(4);
k5 = v(5);
Acetn = Reactants(:,1);
IPrOH = Reactants(:,2);
b =(k1.*k3.*Acetn.*sqrt(k2.*100.)*0.0008.*(1+k1.*Acetn+sqrt(k2.*100)+(k3/k4).*k1.*Acetn.*(IPrOH/k5)).^2 - 6.1E-5);
end
.
Madeline Alzamora
el 21 de Nov. de 2021
Hi! I swapped out the total rate for R_Iso_exp because that's the experimental data that I'm trying to fit kinetics123 to (so that both of them are ~6.1*10^-5). It looks so nice!!! Is there a way to ensure that "EstTotalRate" converges to (6.1*10^-5) definitively without any k values being negative? Just to check, I swapped in fmincon and put in [0 0 0 0 0] for the lower bound, but it keeps reaching .82.
Thank you!!
Data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/808424/kinetics%20project.xlsx', 'VariableNamingRule','preserve');
Reactants = [Data.('Acetone in') Data.('Iso out')];
%TotalRate = sum(Reactants,2);
TotalRate = [Data.('R_Iso_exp')];
% v = [0.1, 0.1, 0.1, 0.1, 0.1];
v = rand(5,1);
[B,fv] = fminsearch(@(b)norm(TotalRate - kinetics1234(b,Reactants)), v)
EstTotalRate = kinetics1234(B,Reactants);
%when you put in fmincon
A = [];
b= [];
Aeq = [];
beq = [];
[B,fv] = fmincon(@(b)norm(TotalRate - kinetics1234(b,Reactants)), v, A, b, Aeq, beq, [0 0 0 0 0], [])
Star Strider
el 21 de Nov. de 2021
This works, although I can’t get a good fit to those data.
Check to see that the objective funciton is coded correctly so that the output of the function is appropriate to the data. I have no idea what the reaction is or how the differential equation system was integrated, so I can’t check thiat myself.
Data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/808424/kinetics%20project.xlsx', 'VariableNamingRule','preserve')
Data = 400×17 table
Acetone in Iso out R_Iso_exp R_Iso_mech Sq Diff Var6 Acetone in_1 Iso out_1 R_Iso_exp_1 R_Iso_mech_1 Sq Diff_1 Var12 Acetone in_2 Iso out_2 R_Iso_exp_2 R_Iso_mech_2 Sq Diff_2
__________ _______ __________ __________ _______ ____ ____________ _________ ___________ ____________ _________ _____ ____________ _________ ___________ ____________ _________
102 0.61038 6.118e-05 NaN NaN NaN 102 3.5818 0.00028721 NaN NaN NaN 102 4.7952 0.00032042 NaN NaN
104 0.60501 6.0642e-05 NaN NaN NaN 104 3.5881 0.00028771 NaN NaN NaN 104 4.8352 0.0003231 NaN NaN
106 0.5992 6.006e-05 NaN NaN NaN 106 3.6137 0.00028977 NaN NaN NaN 106 4.8849 0.00032642 NaN NaN
108 0.59493 5.9632e-05 NaN NaN NaN 108 3.6297 0.00029105 NaN NaN NaN 108 4.9199 0.00032876 NaN NaN
110 0.5903 5.9167e-05 NaN NaN NaN 110 3.6417 0.00029201 NaN NaN NaN 110 4.9597 0.00033141 NaN NaN
112 0.58668 5.8804e-05 NaN NaN NaN 112 3.6558 0.00029315 NaN NaN NaN 112 5.0024 0.00033427 NaN NaN
114 0.58086 5.8222e-05 NaN NaN NaN 114 3.6619 0.00029363 NaN NaN NaN 114 5.0438 0.00033704 NaN NaN
116 0.57643 5.7777e-05 NaN NaN NaN 116 3.6763 0.00029479 NaN NaN NaN 116 5.0806 0.00033949 NaN NaN
118 0.57281 5.7414e-05 NaN NaN NaN 118 3.6839 0.0002954 NaN NaN NaN 118 5.1134 0.00034168 NaN NaN
120 0.56897 5.7029e-05 NaN NaN NaN 120 3.6948 0.00029627 NaN NaN NaN 120 5.157 0.0003446 NaN NaN
122 0.56303 5.6434e-05 NaN NaN NaN 122 3.7038 0.000297 NaN NaN NaN 122 5.178 0.000346 NaN NaN
124 0.5581 5.594e-05 NaN NaN NaN 124 3.7137 0.00029778 NaN NaN NaN 124 5.214 0.00034841 NaN NaN
126 0.55447 5.5576e-05 NaN NaN NaN 126 3.735 0.0002995 NaN NaN NaN 126 5.2546 0.00035112 NaN NaN
128 0.55023 5.5151e-05 NaN NaN NaN 128 3.7462 0.00030039 NaN NaN NaN 128 5.2993 0.00035411 NaN NaN
130 0.54616 5.4743e-05 NaN NaN NaN 130 3.7468 0.00030044 NaN NaN NaN 130 5.3328 0.00035635 NaN NaN
132 0.54246 5.4372e-05 NaN NaN NaN 132 3.762 0.00030166 NaN NaN NaN 132 5.3578 0.00035801 NaN NaN
Reactants = [Data.('Acetone in') Data.('Iso out')];
TotalRate = Data.('R_Iso_exp');
% v = [0.1, 0.1, 0.1, 0.1, 0.1];
v = rand(5,1)*100;
[B,fv] = fminsearch(@(b)norm(TotalRate - kinetics123(b,Reactants)), v)
B = 5×1
0.0000
102.1531
20.5651
83.6655
33.3665
fv = 9.7131e-04
EstTotalRate = kinetics123(B,Reactants);
figure
scatter3(Reactants(:,1), Reactants(:,2), TotalRate, 50, 'p', 'filled')
hold on
plot3(Reactants(:,1), Reactants(:,2), EstTotalRate, '-r')
hold off
grid on
xlabel('CH_3CHO')
ylabel('CH_3CH_2OH')
zlabel('Output')
legend('Data', 'Fitted Regression', 'Location','best')
function b = kinetics123(v,Reactants)
k1 = v(1);
k2 = v(2);
k3 = v(3);
k4 = v(4);
k5 = v(5);
Acetn = Reactants(:,1);
IPrOH = Reactants(:,2);
b =(k1.*k3.*Acetn.*sqrt(k2.*100.)*0.0008.*(1+k1.*Acetn+sqrt(k2.*100)+(k3/k4).*k1.*Acetn.*(IPrOH/k5)).^2 - 6.1E-5);
end
.
Madeline Alzamora
el 21 de Nov. de 2021
!!! I fixed a factor in my equation and played around a little bit in the structure and it's working! The esttotalrate starts off at the appropriate value, and my B values are stabilizing.
I can't thank you enough for helping me! I've been stuck on this for three days and it was driving me insane.
Star Strider
el 21 de Nov. de 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Etiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)