Help to find minimum values of a multivariable function

3 vues (au cours des 30 derniers jours)
BobbyJoe
BobbyJoe le 8 Nov 2020
Commenté : BobbyJoe le 8 Nov 2020
I have the following function "TotalSum.m":
function [SS] = TotalSum(k1,k2,T,A_Ydata,B_Ydata,C_Ydata)
SS = ConcA(k1,T,A_Ydata) + ConcB(k1,k2,T,B_Ydata) + ConcC(k1,k2,T,C_Ydata);
end
function [SSa] = ConcA(k1,T,A_Ydata)
SSa = sum(((exp(-k1.*T)-A_Ydata).^2));
end
function [SSb] = ConcB(k1,k2,T,B_Ydata)
SSb = sum((((k1.*exp(-k2.*T))./(k1 - k2) - (k1.*exp(-k1.*T))./(k1 - k2))-B_Ydata).^2);
end
function [SSc] = ConcC(k1,k2,T,C_Ydata)
SSc = sum((((k2.*exp(-k1.*T))./(k1 - k2) - (k1.*exp(-k2.*T))./(k1 - k2) + 1)-C_Ydata).^2);
end
and the main script "NonLinearExample.m":
%Nonlinear Example
clear all;
clc;
t = [0 2 6 10 20 30 50 70 90 120 150 200];
T = t';
a_ydata = [1 0.88 0.69 0.53 0.28 0.15 0.043 0.012 0 0 0 0];
A_Ydata = a_ydata';
b_ydata = [0 0.12 0.29 0.42 0.55 0.57 0.46 0.33 0.22 0.12 0.06 0.01];
B_Ydata = b_ydata';
c_ydata = [0 0 0.03 0.05 0.16 0.28 0.50 0.66 0.78 0.88 0.94 0.98];
C_Ydata = c_ydata';
k1 = 0.0629595;
k2 = 0.0211523;
k = [k1,k2];
[SS] = TotalSum(k1,k2,T,A_Ydata,B_Ydata,C_Ydata);
K = fminsearch(@(k)TotalSum,k)
I want to minimise the output [SS] as much as possible by varying the values k1 and k2. However, I am unable to do this.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Nov 2020
K = fminsearch(@(k12)TotalSum(k12(1), k12(2), T, A_Ydata, B_Ydata, C_Ydata), k)
  1 commentaire
BobbyJoe
BobbyJoe le 8 Nov 2020
Walter, this line of code just fixed a problem I was having for over 4 hours. You truly deserve MVP recognition.
Thank you so so much!!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by