Can anyone suggest something that could fix the program
Mostrar comentarios más antiguos


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 comentarios
Alex Mcaulley
el 30 de Jul. de 2019
What is your issue? Are you getting any error?
Titu Thomas
el 30 de Jul. de 2019
Respuestas (1)
Prabhan Purwar
el 2 de Ag. de 2019
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:
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
