Hello!
I have two vectors as shown here
volume = 1:7;
pressure = [3102,2385,1344,886,623,452,411];
I want to have them, fit curves to the data with first-,second-, and third-order polynomails. I want to use polyfit and polyval.
Then I want to plot the three fitted functions on the same graph. I think I want to have a stepsize of 0.2m^3 in order to smooth the curves.
Next I want to plot the actual data from the table on the same graph as the fitted curves, With (im not sure if you can do this) unconnected circles
And then finnally I want to use legend lebels like this 1st order, 2nd order,3rd order and original data.
And would it be possible to treat the volume as the independent (x) variable and treat the pressure as the dependent (y) variable?
Would any of you be able to help me with this?
Please let me know
Thanks

3 Kommentare

Star Strider
Star Strider am 6 Aug. 2021
This sounds suspiciously like homework!
See the relevant function documentation for examples on how to do all of this.
.
Daniel Vonderhaar
Daniel Vonderhaar am 6 Aug. 2021
I sware this is not homework. I guess It does sound like homework. Im sorry. Im just trying to get some help.
John D'Errico
John D'Errico am 6 Aug. 2021
While it may not have been explicitly homework, it is still surely a student project of some sort, that should arguably have been treated as homework.
And will you please stop titling EVERY question of yours with "I need some help please?"

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Star Strider
Star Strider am 6 Aug. 2021

0 Stimmen

I sware this is not homework. I guess It does sound like homework. Im sorry. Im just trying to get some help.
O.K. I’ll take you at your word.
volume = 1:7;
pressure = [3102,2385,1344,886,623,452,411];
vv = min(volume):0.2:max(volume);
pv = zeros(3,numel(vv));
for k = 1:3
p{k} = polyfit(volume,pressure,k);
pv(k,:) = polyval(p{k}, vv);
end
figure
hold on
for k = 1:3
plot(vv, pv(k,:), 'DisplayName',sprintf('Polynomial Fit Order %d',k))
end
scatter(volume,pressure,'filled', 'DisplayName','Data')
hold off
grid
legend('Location','best')
xlabel('Volume')
ylabel('Pressure')
Make appropriate changes to get the result you want.
.

2 Kommentare

Daniel Vonderhaar
Daniel Vonderhaar am 6 Aug. 2021
Thank you for your help!
Star Strider
Star Strider am 6 Aug. 2021
As always, my pleasure!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-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