How to find parameters that minimize a difference

Hi everyone, I have to solve an equation numerically. I thought to split it into two parts and to calculate the difference between them setting a first try column vector and 4 first try parameters. How can I get the 4 parameters that minimize the obtained column of differences? Thank you.
Here is the code for the first part:
k=1.53E4;
kp=5.8E4;
c=1.11E6;
g=1; %first try parameters
t=[2:2:480]';
x=Strain; %Strain is a column vector 240x1
y=[zeros(1,length(x))]';
y1=((c./t).*x.*(exp(-k.*t/c)).*(-1+exp(k.*t./c))+x.*kp);
y2=(54000-x.*g.*(1-exp(x)).^2);
for i=1:(length(x))
y(i)=y1(i)-y2(i);
end

Réponses (1)

Use fminsearch and use the norm of the differences.
help fminsearch

3 commentaires

vinxp
vinxp le 9 Nov 2021
Modifié(e) : vinxp le 9 Nov 2021
Sorry for my slow response and thank you. So I need parameters k, kp and c that minimize the difference between x (experimental) and x evaluated. I tried to do something like this, keeping constant two parameters (kp and c) and varying k. How can i do something similar with a for loop?
g=1;
k=[1.5E4 1.4E4 1.3E4];
kp=5.8E4;
c=1.11E6;
s=54000*ones(1,240)';
x=Strain;
t=[2:2:480]';
argmin_x=@(x)norm(((c./t).*x.*(exp(-k(1).*t./c)).*(-1+exp(k(1).*t./c))+x.*kp)-((s-x.*g.*(1-exp(x)).^2)));
x0=x;
[x1,normval1] = fminsearch(argmin_x, x0);
argmin_x=@(x)norm(((c./t).*x.*(exp(-k(2).*t./c)).*(-1+exp(k(2).*t./c))+x.*kp)-((s-x.*g.*(1-exp(x)).^2)));
x0=x;
[x2,normval1] = fminsearch(argmin_x, x0);
argmin_x=@(x)norm(((c./t).*x.*(exp(-k(3).*t./c)).*(-1+exp(k(3).*t./c))+x.*kp)-((s-x.*g.*(1-exp(x)).^2)));
x0=x;
[x3,normval1] = fminsearch(argmin_x, x0);
More like this (though I can't test it as I don't have the Strain values).
k=1.5E4;
kp=5.8E4;
c=1.11E6;
k_kp_c0 = [k, kp, c];
s=54000*ones(1,240)';
x=Strain;
[K,normval1] = fminsearch(@(k_kp_c) argmin_x(k_kp_c, x), k_kp_c0);
k = K(1);
kp = K(2);
c = K(3);
function F = argmin_x(k_kp_c, x)
k = k_kp_c(1);
kp = k_kp_c(2);
c = k_kp_c(3);
g = 1;
t=(2:2:480)';
x_comp = ((c./t).*x.*(exp(-k.*t./c)).*(-1+exp(k.*t./c))+x.*kp)-((s-x.*g.*(1-exp(x)).^2));
F = norm(x_comp - x);
end
Alan Stevens
Alan Stevens le 10 Nov 2021
Modifié(e) : Alan Stevens le 10 Nov 2021
deleted

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2018a

Question posée :

le 8 Nov 2021

Modifié(e) :

le 10 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by