How do I set coefficient variables in Fittype that was generated in Fitting toolbox?
10 ビュー (過去 30 日間)
古いコメントを表示
Hello.
I am trying to fitting some equations to my data and here I am using Fittype which was generated by Curve Fitting Application. The fitting function is below.
I am wondering how I can set coefficient on this equation.
For example, the current equation is
A1*exp(B1*-2.7)*exp(-1*Ea1/8.62e-5*(1/(273+105)))*log(1+C*x)+A2*exp(B2*-2.7)*exp(-Ea2/8.62e-5*(1/(273+105)))*x^n1
but I wanted to change this to
A1*exp(B1*V)*exp(-1*Ea1/8.62e-5*(1/(273+T)))*log(1+C*x)+A2*exp(B2*V)*exp(-Ea2/8.62e-5*(1/(273+T)))*x^n1
The values of V and T will be given in the script. V = [-1.8 -2.7 -3.0] and T = [30 70 105]
The fitting function as of now, if I wanted to run with different V (voltage), I need to generate another fitting function.
I would really appreciate if you provide any input to go through it. Thank you!
======================================================
function [fitresult, gof] = testfitstress(ts, y_Ts)
%% Fit: 'fitstress'.
[xData, yData] = prepareCurveData( ts, y_Ts );
% Set up fittype and options.
ft = fittype( 'A1*exp(B1*-2.7)*exp(-1*Ea1/8.62e-5*(1/(273+105)))*log(1+C*x)+A2*exp(B2*-2.7)*exp(-Ea2/8.62e-5*(1/(273+105)))*x^n1', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.538342435260057 0.996134716626885 0.106652770180584 0.86869470536351 0.0781755287531837 0.0844358455109103 0.399782649098896 0.259870402850654];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
======================================================
3 件のコメント
Matt J
2022 年 7 月 29 日
編集済み: Matt J
2022 年 7 月 29 日
Note that expressions like this,
A1*exp(B1*V)*exp(-1*Ea1/8.62e-5*(1/(273+T)))
and,
A2*exp(B2*V)*exp(-Ea2/8.62e-5*(1/(273+T)))
do not involve the independent variable x and can take on any value by suitable selection of A1 and A2. They can therefore be replaced with single coefficients Q1 and Q2, simplifying the model to
y = Q1*log(1+C*x)+ Q2*x^n1
Not to do so gives you a highly over-parametrized problem.
Once you have fitted Q1 and Q2, you can explore valid values for the original parameters by considering the equations,
A1*exp(B1*V)*exp(-1*Ea1/8.62e-5*(1/(273+T))) = Q1
A2*exp(B2*V)*exp(-Ea2/8.62e-5*(1/(273+T))) = Q2
for different values of T and V. However, because this is a system of 2 equations in 6 unknowns, you should expect that many possible solutions exist.
採用された回答
Matt J
2022 年 7 月 29 日
編集済み: Matt J
2022 年 7 月 29 日
Instead of a fitType object, use an anonymous function like in this example,
Vset = [-1.8 -2.7 -3.0]; Tset = [30 70 105]
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.538342435260057 0.996134716626885 0.106652770180584 0.86869470536351 0.0781755287531837 0.0844358455109103 0.399782649098896 0.259870402850654];
for i=1:numel(Vset)
V=Vset(i); T=Tset(i)
fitFun=@(A1,B1,A2,B2...,x) A1*exp(B1*V)*exp(-1*Ea1/8.62e-5*(1/(273+T)))*...
log(1+C*x)+A2*exp(B2*V)*exp(-Ea2/8.62e-5*(1/(273+T)))*x.^n1;
[fitresult{i}, gof{i}] = fit( xData, yData, fitFun, opts );
end
2 件のコメント
Matt J
2022 年 7 月 30 日
You're quite welcome, but please Accept-click the answer to indicate that it worked.
その他の回答 (1 件)
Steven Lord
2022 年 7 月 31 日
On the documentation page for the fittype function, see the "Use Anonymous Functions to Work with Problem Parameters and Workspace Variables" example that has a problem-dependent parameter c (which is not a coefficient to be fit) and how that problem-dependent parameter is assigned a value when the fit is performed.
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!