Help to find minimum values of a multivariable function

조회 수: 2 (최근 30일)
BobbyJoe
BobbyJoe 2020년 11월 8일
댓글: BobbyJoe 2020년 11월 8일
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.

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 8일
K = fminsearch(@(k12)TotalSum(k12(1), k12(2), T, A_Ydata, B_Ydata, C_Ydata), k)
  댓글 수: 1
BobbyJoe
BobbyJoe 2020년 11월 8일
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!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by