how to compute the best first order (linear) fits of the forms y = mx+b and y = Ce^dx?

5 Ansichten (letzte 30 Tage)
How can I compute these forms and display the values for a,b,C, and d? My code is below.
% creates a graph with a line of best fit
rideData % contains arrays of data for climb and calories
figure(1);
plot(climb, calories, "o");
p = polyfit(climb, calories, 1);
f = polyval(p, climb);
hold on
plot(climb, f);

Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Dez. 2018
What is a?
Did you see my answer here in this recent question
To display values, plug them into sprintf() and then use helpdlg(), msgbox(), text(), or fprintf() to display them.
Your p(1) is your m.
Your p(2) is your b.
To fit to an exponential, use fitnlm() like the attached example shows.
  5 Kommentare
Image Analyst
Image Analyst am 22 Apr. 2019
He said "display the values for a,b,C, and d" but he never said what c and d were so I can't answer the question completely. Obinna, you might want to start your own question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by