Can anyone suggest something that could fix the program
조회 수: 1 (최근 30일)
이전 댓글 표시
clear all
clc
%following line calls my data
[xdataini, ydataini] = textread('data.txt','%f %f','headerlines',0);
figure;
plot(xdataini,ydataini,'ok')
ylim([0,1]);
xlim([0,0.25]);
%warning off MATLAB:divideByZero
xdata=xdataini(1:245);
ydata=ydataini(1:245);
x0=[1,1];
[x]=lsqcurvefit(@subprogramTL,x0,xdata,ydata);
V=subprogramTL([x],xdata);
fid = fopen('data1.txt','w');
fprintf(fid,'%3.5f \n',V);
fclose(fid);
hold on
plot (xdata,V,'r')
hold off
SUBPROGRAM
function F=subprogramTL(x,xdata)
m = 5.8;
v = 1.7;
F=(1-((x(1)/2).*atan((2.*m.*v)/((1+2.*m)^2 + v^2)*(x(2)./(2*xdata)) + 1 + 2.*m + v.^2))).^2;
%+ ((x(1)/4).*log(((1+((2*m)./(1+(2*xdata)/x(2)))).^2 + v.^2)/((1+(2*m)).^2 +v.^2)).^2);
end
댓글 수: 2
답변 (1개)
Prabhan Purwar
2019년 8월 2일
Code is working perfectly fine. The output of lsqcurvefit() function is the best fit of variables and depends upon assigned model. For more information refer to following link:
As the data appears to be like an exponential function, then I would suggest you make use of fit() function with appropriate fittype and fitoption as explained in the following example.
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(cdate)],...
'StartPoint',[1 1]);
ft = fittype('a*(x-b)^n','problem','n','options',fo);
[curve2,gof2] = fit(cdate,pop,ft,'problem',2)
For more information refer to following link:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!