Data fitting weibull and integration

조회 수: 6 (최근 30일)
Nuno
Nuno 2011년 4월 18일
Hi all, first of all let me say that i'm a bit inexperienced regrading programming and Matlab. I have made a m file with a bit of code that tries to fit a weibull distribution function to some data from a excel file. this part is done by the code but i also want to do a definite integral on that function multiplied by x but i always get the same error, says that cannot find explicit integral... i don't know if the problem is because of the function hand le or other thing... any suggestions?
CODE:
clc
% Vectors (x, fi) to create histogram with the experimental data for length
%%#1
% Go to excel spreadsheet and retrieve the data for x, fi, vectors
fi = xlsread('C:\Users\Nuno\Documents\MATLAB\dados_raiz_working.xlsx','Dados raiz','f4:f42');
x = xlsread('C:\Users\Nuno\Documents\MATLAB\dados_raiz_working.xlsx','Dados raiz','b4:b42');
Lmean=xlsread('C:\Users\Nuno\Documents\MATLAB\dados_raiz_working.xlsx','Weibull','o7')
%bar graph
bar(x,fi)
fi=fi';
x=x';
%%#2
% Weibull function
modelFun = @(p,x) p(3) .* (x ./ p(1)).^(p(2)-1) .* exp(-(x ./ p(1)).^p(2));
startingVals = [2.6057 0.67657 1];
coefEsts = nlinfit(x', fi', modelFun, startingVals)
xgrid = x;
%%#3
%Writes on excel spreadsheet the data obtained from weibull distribuiton
write_column_excel=xlswrite('C:\Users\Nuno\Documents\MATLAB\dados_raiz_working.xlsx',modelFun(coefEsts, xgrid)', 'Weibull', 'D3');
%%#4
% line graph
line(xgrid, modelFun(coefEsts, xgrid), 'Color','red','LineWidth',2.5)
title('\fontsize{14}Histograma com distribuição de Weibull')
xlabel('\fontsize{12}Comprimentos(mm)');
ylabel('\fontsize{12}Frequência (%)')
h = legend('Dados Raiz','Distribuição Weibull',1);
set(h,'Interpreter','none')
text(1.28,6,[{'\bf \fontsize{12}Goodness of fit'}])
text(1.3,5,['SSE=19.65'])
text(1.3,4.4,['R^2=0.94'])
text(1.3,3.8,['RMSE=0.7387'])
hold on
%%#5
%In here i try to determine a specific coeficient that is obtained by definite integration between 0 and inf of the weibull function multiplied by "x" and (1/Lmean) (PROBLEM!!).
a=coefEsts(1); %Coeficientes dados pelo método de regressão linear
b=coefEsts(2); %na célula 3
c=coefEsts(3);
syms x
modelFun = @(x) c .* (x ./a).^(b-1) .* exp(-(x ./ a).^b);
Coef_ajust_length=eval(int(modelFun(x)*x*(1/Lmean), x, 0, inf));
  댓글 수: 1
Nuno
Nuno 2011년 4월 19일
I've changed the code as proecsm suggested but it gives the same error, "explicit integral could not be found".... the error occurs on the #5 cell when i try to do the integration of "modelFun(x)*x" if i do it without the multiplication by "x" it doesn't give me errors...

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

채택된 답변

bym
bym 2011년 4월 19일
I had no problem getting an answer using assumed values for a,b,c. Upon closer inspection, you are using x as both a numeric variable as in :
x = xlsread('C:\Users\Nuno\Documents\MATLAB\dados_raiz_working.xlsx','Dados raiz','b4:b42');
and as symbolic
syms x
I would suggest using different variables names and see if the warning goes away. As for you comment about the fractions, symbolic computations return answers as exact rational expressions instead of floating point approximations (i.e. 1/3 instead of .33333...)

추가 답변 (2개)

bym
bym 2011년 4월 18일
you have not defined the variable p in your function. just use
ModelFun = @(x)c .* (x ./a).^(b-1) .* exp(-(x ./ a).^b)
  댓글 수: 2
bym
bym 2011년 4월 18일
also, drop the eval() from your integration
Nuno
Nuno 2011년 4월 19일
If i dont use eval() the result doesn't appear, but instead a fraction... like 1234567890/0987654321...! don't know why this happens...

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


Nuno
Nuno 2011년 4월 19일
Hi, just to let you know that i think i solve my problem, in the integration part of my code, i jut add the double() part:
Coef_ajust_length=double(int(modelFun(x)*x*(1/Lmean), x, 0, inf));
the warning still appears, but i now get a result.
Don't know if this is the best way to solve the problem, but it seems to get the job done.
Thank you

제품

Community Treasure Hunt

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

Start Hunting!

Translated by