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...
Data fitting weibull and integration
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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));
Réponse acceptée
bym
le 19 Avr 2011
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...)
0 commentaires
Plus de réponses (2)
bym
le 18 Avr 2011
you have not defined the variable p in your function. just use
ModelFun = @(x)c .* (x ./a).^(b-1) .* exp(-(x ./ a).^b)
2 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!