non linear fitting using two input variables and seven parameters
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Remi Blanchard
am 25 Jan. 2019
Beantwortet: Remi Blanchard
am 25 Jan. 2019
Hi,
I have developped a program to fit my expeirmental data to a model, the program run, but the fit is just digusting (and I have an exiflag=1 that does not make any sense)
Here is the main :
clc % clear command window
clear all % efface toutes les variables
close all % ferme toutes les figures
% load NiCr.txt
load Pt.txt
% load NiCup.txt
Pot= Pt(:,1);
CurExp=Pt(:,2);
% Pot= NiCr(:,1);
% CurExp=NiCr(:,2);
% Pot= NiCup(:,1);
% CurExp=NiCup(:,2);
x0=[0.000000001 0.00000000001 0.5 0.5]; % first vector to be adjusted if necessary
%ub mean upper limit, values can be played with, if necessary
ubk1 = 0.0001;
ubk2 = 0.0001 ;
ubalpha = 1 ;
ConC = H2conc(CurExp) ;
Longueur= size(Pot);
for i = 1 : Longueur
x = [ Pot(i),ConC(i) ] ;
Input(i,:)=x ;
end
% % BEFORE RUNNING PROGRAM, ENSURE THAT THE TEMPERATURE IS CHANGED IN THE
% % FOUR FUNCTIONS
options = optimset('Tolfun',1e-40);
[sol, resnorm,residual,exitflag,output]=lsqcurvefit( 'Model', x0, Input,CurExp,[0 0 0 0],[ubk1 ubk2 ubalpha ubalpha],options)
CurCal =Model(sol, Input);
% % VthetaS=thetaS(sol, Pot);
% % VthetaH=thetaH(sol, Pot);
% VthetaHydride=thetaHydride(sol, Pot);
% VthetaSH=thetaSH(sol, Pot) ;
% VthetaSH2=thetaSH2(sol, Pot) ;
hold all
plot(Pot, CurCal, 'g*-')
plot(Pot, CurExp, 'r+')
title('Comparaison modele vs experience');
xlabel('Potential');
ylabel('Current');
% outputdata = [Pot CurExp CurCal residual VthetaS VthetaH VthetaHydride VthetaSH VthetaSH2];
And the functions I have created :
model.m
function [Y] = Model(x, Input)
k1 = x(:,1);
k2 = x(:,2);
alphao1 = x(:,3);
alphao2 = x(:,4) ;
Pot= Input(:,1) ;
ConC= Input(:,2);
% H2conc = 0.0017.*(Pot).^4-0.0034.*(Pot).^3+0.0003.*(Pot).^2-9.*10.^-6.*Pot+10.^-7 ;
% H2conc = 7.29475235532999e-08 ;
Eth1 = 0; %Value for volmer and heyvroskuy
tau = 2.2.*10.^-9; %enter here the value of tau determined for the catalyst, at the correct temperature
temp = 298;% adjust here the value of the temperature used for the experiment in Kelvin
f = 96500./(8.314.*temp);
Var1 = k1.*exp(alphao1.*f.*(Pot+Eth1)) ; % Ko1
Var2 = k2.*exp(alphao2.*f.*(Pot+Eth1)) ; %KO2
Y = (2.*tau.*96500.*Var1.*Var2)./(1./ConC + Var2./ConC + Var1) ;
end
and H2conc.m
function [Z] = H2conc(CurExp)
m = 0.62.*(5.11.*10.^-5).^(2./3).*12.94.*(10.^-2).^(-1/6); % D taken from Difusion of H2 in water at 298K ; kinematic viscosity of water at 298 K
idm = 3.72E-04 ;
Z =(idm-CurExp)./(96500.*m) ;
end
When I run the program, it is saying that the program have found a local minimum, but here is the comparison between the experimental data (red) and the fit (green)
The fit is obviously not good.
I have tried to modify the program and changing he upper and lower bounds, as well as x0, but it always give me that disgusting fit.
Any suggestions?
Thanks for your help and your time!
Remi
2 Kommentare
John D'Errico
am 25 Jan. 2019
Bearbeitet: John D'Errico
am 25 Jan. 2019
We don't have your data. How can we help you if you provide only part of the information, but none of the important stuff?
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!