How to plot the best fit when x-axis has only one value?

1 visualizzazione (ultimi 30 giorni)
Hi everyone, my data and code is given below,
x1 = [9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,];
x2= [39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27];
y1=[2.49849031538000e-15,2.49502658466163e-15,2.49502495000000e-15,2.50264303379900e-15,2.49502658466163e-15,2.49502495000000e-15,2.49560122336855e-15,8.17662331186994e-16,6.29990432061625e-16,2.12956584547500e-15,1.91935478762000e-15,2.63195081946000e-15,3.12979948175000e-15,3.09444418405000e-15,3.09233615855000e-15,3.01050170545000e-15,3.06054718890000e-15,3.11567416400000e-15,3.13276918045000e-15,3.05145014445000e-15,2.99728379425000e-15,3.12172508790000e-15,2.56985506485000e-15,3.20864482505000e-15,2.97324731355000e-15,2.56209731145000e-15,1.64972623540000e-15,1.62535722858500e-15,1.54636514685000e-15,1.28859402225000e-15,1.46049846936000e-15,1.33810415355000e-15,1.14215819083000e-15,8.42920403255000e-16];
y2=[1.50485306240000e-18,1.50775125440000e-18,1.34939445270000e-18,1.46522490255000e-18,1.29700159840000e-18,1.07510058980000e-18,1.18186725355000e-18,6.96921304120000e-18,1.10896235555000e-18,1.88431177410000e-18,2.06954144735000e-18,3.69742782500000e-18,4.50267051220000e-18,5.18527090055000e-18,4.27703042175000e-18,4.08381752195000e-18,4.36270874670000e-18,3.90556129885000e-18,3.54560734945000e-18,2.57385028340000e-18,2.66198817935000e-18,3.65437028765000e-18,2.19580890635000e-18,2.08296552040000e-18,1.69517276020000e-18,1.56244075620000e-18,1.34416563130000e-18,1.63989745735000e-18,1.61394252125000e-18,1.55418026030000e-18,1.42952255035000e-18,1.29278442465000e-18,1.16687040735000e-18,1.29804106530000e-18];
loglog(x1,y1,'*b')
hold on
loglog(x2,y2,'*r')
I need the first order best fit of this data and code,thanks.
  3 Commenti
the cyclist
the cyclist il 10 Gen 2018
It's not very clear what your goal is for this "fit". Do you want to predict or simulate values for x1 and x2 separately?
Are your trying to predict y values for values of x that are different from your x1 and x2? (That seems like a fool's errand.)
You need to tell us more about what you are planning to do with this fit.
Safi ullah
Safi ullah il 10 Gen 2018
I need to find best fit line between the red and blue points

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 10 Gen 2018
Try this:
x1 = [9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,9.384,];
x2= [39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27,39.27];
y1=[2.49849031538000e-15,2.49502658466163e-15,2.49502495000000e-15,2.50264303379900e-15,2.49502658466163e-15,2.49502495000000e-15,2.49560122336855e-15,8.17662331186994e-16,6.29990432061625e-16,2.12956584547500e-15,1.91935478762000e-15,2.63195081946000e-15,3.12979948175000e-15,3.09444418405000e-15,3.09233615855000e-15,3.01050170545000e-15,3.06054718890000e-15,3.11567416400000e-15,3.13276918045000e-15,3.05145014445000e-15,2.99728379425000e-15,3.12172508790000e-15,2.56985506485000e-15,3.20864482505000e-15,2.97324731355000e-15,2.56209731145000e-15,1.64972623540000e-15,1.62535722858500e-15,1.54636514685000e-15,1.28859402225000e-15,1.46049846936000e-15,1.33810415355000e-15,1.14215819083000e-15,8.42920403255000e-16];
y2=[1.50485306240000e-18,1.50775125440000e-18,1.34939445270000e-18,1.46522490255000e-18,1.29700159840000e-18,1.07510058980000e-18,1.18186725355000e-18,6.96921304120000e-18,1.10896235555000e-18,1.88431177410000e-18,2.06954144735000e-18,3.69742782500000e-18,4.50267051220000e-18,5.18527090055000e-18,4.27703042175000e-18,4.08381752195000e-18,4.36270874670000e-18,3.90556129885000e-18,3.54560734945000e-18,2.57385028340000e-18,2.66198817935000e-18,3.65437028765000e-18,2.19580890635000e-18,2.08296552040000e-18,1.69517276020000e-18,1.56244075620000e-18,1.34416563130000e-18,1.63989745735000e-18,1.61394252125000e-18,1.55418026030000e-18,1.42952255035000e-18,1.29278442465000e-18,1.16687040735000e-18,1.29804106530000e-18];
xv = reshape([x1; x2], [], 1); % Create X-Vector
YM = reshape([y1; y2], [], 1); % Create Y-Vector
DM = [xv(:) ones(size(xv(:)))]; % Design Matrix
B = DM \ YM; % Estimate Parameters
YFit = DM * B; % Fit Regression For Plot
YFit = reshape(YFit, 2, [])';
figure(1)
loglog(x1,y1,'*b')
hold on
loglog(x2,y2,'*r')
plot([x1(1) x2(1)], YFit(1,:), '-pg')
hold off

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by