Fit Model to Data

조회 수: 1 (최근 30일)
mehtap agirsoy
mehtap agirsoy 2021년 4월 16일
답변: mehtap agirsoy 2021년 4월 16일
Hello there,
I have a question regardind fitting model to data. I have 3 models, my problem is with time constant. Time constant parameters that are coming out of time vector, T, rather than parameter vector, P. This effectively gives them fixed values for time constants that are far too low. All of the models should fit the data fairly well. I ccould not figure it out and need help.
Main code is
close all; clear all;
% SET CALIBRATION CONSTANT
CF = 2.1931;
% LOAD DATA FILE
[fname,pname] = uigetfile('*.txt','LOAD DATA FILE');
DAT = dlmread([pname,'\',fname]);
% TIME IS COLUMN 1, DISPLACEMENT IS COLUMN 2
TIME = DAT(:,1);
DISP = CF*DAT(:,2); % APPLY CALIBRATION TO DISPLACEMENT
% CLIP AT 59.9s
IN = find(TIME >= 59.9);
TIME = TIME(IN);
DISP = DISP(IN);
% ZERO INITIAL AND FLIP DISPLACEMENT
TIME = TIME - TIME(1);
DISP = -DISP + DISP(1);
Y=DISP;
% DEFINE FUNCTION
[YM1] = MODEL_1(TIME,Y);
[YM2] = MODEL_2(TIME,Y);
[YM3] = MODEL_3(TIME,Y);
YM=[YM1 YM2 YM3];
My model function is
function [YM1] = MODEL_1(TIME,Y)
MODEL = @(P,T) P(1)+P(2).*(1-exp(-T./T(3)));
P0 = [0,1,1]; % INITIAL GUESS VALUES FOR PARAMETERS
PF = lsqcurvefit(MODEL,P0,TIME,Y);
YM1 = MODEL(PF,TIME);
% CALCULATE ADJUSTED R^2 HERE
Ybar = mean(Y); % AVERAGE OBSERVED
SStot = sum( (Y - Ybar).^2 ); % TOTAL SUM OF SQUARES
SSres = sum( (Y - YM1).^2 ); % RESIDUAL SUM OF SQUARES
R2 = 1 - SSres/SStot; % R SQUARED
n = length(Y); % NUMBER OF OBSERVATIONS
p = length (PF); % NUMBER OF PARAMETERS
Rbar2 = 1 - (1 - R2)*(n - 1)/(n - p - 1);
disp(['R^2 = ',num2str(R2),', ADJUSTED R^2 = ',num2str(Rbar2)])
end
and main code is
close all; clear all;
% SET CALIBRATION CONSTANT
CF = 2.1931;
% LOAD DATA FILE
[fname,pname] = uigetfile('*.txt','LOAD DATA FILE');
DAT = dlmread([pname,'\',fname]);
% TIME IS COLUMN 1, DISPLACEMENT IS COLUMN 2
TIME = DAT(:,1);
DISP = CF*DAT(:,2); % APPLY CALIBRATION TO DISPLACEMENT
% CLIP AT 59.9s
IN = find(TIME >= 59.9);
TIME = TIME(IN);
DISP = DISP(IN);
% ZERO INITIAL AND FLIP DISPLACEMENT
TIME = TIME - TIME(1);
DISP = -DISP + DISP(1);
Y=DISP;
% DEFINE FUNCTION
[YM1] = MODEL_1(TIME,Y);
[YM2] = MODEL_2(TIME,Y);
[YM3] = MODEL_3(TIME,Y);
YM=[YM1 YM2 YM3];
  댓글 수: 2
Image Analyst
Image Analyst 2021년 4월 16일
Unfortunately you forgot to attach any .txt files so no one can do anything with that code.
I guess you blew right past the posting guidelines. But luckily you can read them now. They are in the "Community Guidelines" link below or here's another one:
Make it easy for us to help you, not hard. We'll check back later for the txt file.
Star Strider
Star Strider 2021년 4월 16일
Here the function lists 2 parameters, however the initial estimat vector is for 3:
MODEL = @(P,T) P(1)+P(2).*(1-exp(-T./T(3)));
P0 = [0,1,1]; % INITIAL GUESS VALUES FOR PARAMETERS
Should ‘MODEL’ be:
MODEL = @(P,T) P(1)+P(2).*(1-exp(-T./P(3)));
instead?
Also, 0 is never a good initial choice for a parameter estimate.

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

채택된 답변

mehtap agirsoy
mehtap agirsoy 2021년 4월 16일
Many thanks

추가 답변 (1개)

mehtap agirsoy
mehtap agirsoy 2021년 4월 16일
Thanks for the quideline. I will update my question and will insert .txt file.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by