Curve fit but only for the values that exists with defined values of x.
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Yashvardhan Bhati
il 19 Ott 2022
Commentato: Yashvardhan Bhati
il 20 Ott 2022
I wnat to fit the curve for the point but i only want the curve to fit from value suppose in given code x vary from 1800-1950 and shouldn't extend beyond it. Is there any way to do this?
load census
plot(cdate,pop,'o')
%Create a fit options object and a fit type for the custom nonlinear model , where a and b are coefficients and n is a problem-dependent parameter.
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(cdate)],...
'StartPoint',[1 1]);
ft = fittype('a*(x-b)^n','problem','n','options',fo);
%Fit the data using the fit options and a value of n = 2.
[curve2,gof2] = fit(cdate,pop,ft,'problem',2)
%Fit the data using the fit options and a value of n = 3.
[curve3,gof3] = fit(cdate,pop,ft,'problem',3)
%Plot the fit results with the data.
hold on
plot(curve2,'m')
plot(curve3,'c')
legend('Data','n=2','n=3')
hold off
0 Commenti
Risposta accettata
Torsten
il 19 Ott 2022
Modificato: Torsten
il 19 Ott 2022
load census
I = cdate >= 1850 & cdate <= 1950;
cdate1 = cdate(I);
pop1 = pop(I);
plot(cdate,pop,'o')
%Create a fit options object and a fit type for the custom nonlinear model , where a and b are coefficients and n is a problem-dependent parameter.
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(cdate)],...
'StartPoint',[1 1]);
ft = fittype('a*(x-b)^n','problem','n','options',fo);
%Fit the data using the fit options and a value of n = 2.
[curve2,gof2] = fit(cdate1,pop1,ft,'problem',2)
%Fit the data using the fit options and a value of n = 3.
[curve3,gof3] = fit(cdate1,pop1,ft,'problem',3)
%Plot the fit results with the data.
hold on
plot(cdate1,curve2(cdate1),'m')
plot(cdate1,curve3(cdate1),'c')
legend('Data','n=2','n=3')
hold off
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!