Fit a equation to a scatter plot in log log scale with the given parameters
조회 수: 6 (최근 30일)
이전 댓글 표시
I want to fit a curve (equation is known) to a scatter plot (attached image). But, I don't see any curve overlapping with the scatter plot after running the code. It is so easy to do in excel but in MATLAB I am not able to replicate the same. Here is the code with the equation and the parameters:
A=readmatrix('Data_1.xlsx');
x=A(:,1);
y=A(:,2);
z=A(:,3);
q=1.12;
m=400;
z=(1-(1-q)*x*m).^1./(1-q);
sz=15;
scatter(x,y,sz,'MarkerEdgeColor','k','MarkerFaceColor',[1 0 0],'LineWidth',1)
hold on
plot(x,z)
You can also change the values of 'q' and 'm' to obtain the desired curve fitting the scatter plot.
Data and the image is attached.
댓글 수: 0
답변 (1개)
dpb
2023년 4월 10일
이동: dpb
2023년 4월 10일
fn='https://www.mathworks.com/matlabcentral/answers/uploaded_files/1350879/Data_1.xlsx';
A=readmatrix(fn);
x=A(:,1);
y=A(:,2);
%z=A(:,3);
q=1.12;
m=400;
z=(1-(1-q)*x*m).^1./(1-q);
whos z
%sz=15;
%scatter(x,y,sz,'MarkerEdgeColor','k','MarkerFaceColor',[1 0 0],'LineWidth',1)
%hold on
plot(x,z)
hold on
plot(x,A(:,3))
legend('functional','raw data')
You redefine z and your values computed with the specific parameters are far removed from the actual data valus -- and are in fact, negative. Those won't be able to be plotted on a log axis; you undoubtedly got a warning message about that problem.
If have Curve Fitting TB, you could define the model and fit it to estimate the parameters although you may need better starting estimates to at least make the results positive. I've got another engagement at the moment so can't try it jut now...
댓글 수: 1
dpb
2023년 4월 10일
fn='https://www.mathworks.com/matlabcentral/answers/uploaded_files/1350879/Data_1.xlsx';
A=readmatrix(fn);
x=A(:,1);
y=A(:,2);
q=1.12;
m=400;
ft=fittype('(1-(1-q)*x*m).^1/(1-q)');
[f,~,o]=fit(x,y,ft)
plot(f)
hold on
scatter(x,y)
Your model doesn't look to be able to put any curvature to speak of into the result -- not knowing the origins of the data nor the reasons for the particular model form (and other time pressures), I didn't do any further investigation as to what might be a suitable model.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!